backup script to google drive that can be used for multiple directories
<p>this zips the content of the target directory and then uploads it to a google drive backup location</p>
<p>just create a file called ~/<strong>backupdir.sh</strong> and then add the following</p>
<h4>BASH - <strong>backupdir.sh</strong> </h4>
<pre><code class="html hljs xml">tar -czvf ~/backup/$1.tar.gz /var/www/html/$1/<br />rclone copy ~/backup/$1.tar.gz gdrive:Backup/my.server.name</code></pre>
<p>make sure you chmod +x the ~/<strong>backupdir.sh </strong>file</p>
<p>then create another file called <strong>backupsites.sh</strong> and also chmod +x this file</p>
<p>Now we can list the directories we want to zip and upload to google drive.</p>
<h4>BASH - backupsites.sh</h4>
<pre><code class="html hljs xml">#files<br />~/backupdir.sh my.site.one<br />~/backupdir.sh my.site.two</code></pre>
<p>and then when you add a new directory that needs to be backed up to google drive, just add it to the backupsites.sh file and it will add it to the list.</p>
<p>Also if you want to have automated backups you can now add the backupsites.sh to a crontab and specify when you want it to run to automatically backup your files. </p>
<p>Add this to your crontab to backup all sites daily at 8.</p>
<h4>BASH - crontab</h4>
<pre><code class="html hljs xml">0 8 * ~/backup_all.sh > /dev/null 2>&1</code></pre>
<p>⚙</p>