simple backup to google drive fron linux
<p>i added these scripts a while ago to backup mysql databases and web files to google drive a while ago, i just run them on a daily cron to copy the backups every day.</p>
<h3>the files</h3>
<p><img src="https://i.imgur.com/q5ua0sn.png" /></p>
<p>so the bain backupall.sh script runs all the backups, and then the backup scripts can be run per directory or database, so the backupall.sh just connects the scripts together and is the one that is added to the daily cron.</p>
<h3>simple loop backup per directory</h3>
<p>i used to run this one to just add the files in each folder to their own directory, but it didnt upload them to google drive and its missing the mysql databases so its limited, this one isnt part of the main backup but its a good example if you want to keep things local.</p>
<h4>BASH</h4>
<pre><code class="javascript hljs">for d in /var/www/html/*/ ; do<br /> echo "$d"<br /> tar -zcvf /var/www/backup/$d.tar.gz $d<br />done</code></pre>
<h3>backupall.sh</h3>
<p>the main script this will backup a mysql database called kruxordb into kruxordb.sql.tar.gz and upload it to google drive.</p>
<h4>BASH</h4>
<pre><code class="html hljs xml">#mysql<br />./backupmysql.sh kruxordb<br /><br />#files<br />~/backupfiles.sh kruxor.com</code></pre>
<h3>backupfiles.sh</h3>
<p>this one compresses all the files in the target location and then uploads them to google drive.</p>
<h4>BASH</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/nerd.kruxor.com</code></pre>
<h3>backupmysql.sh</h3>
<p>and this dumps the target database to a .sql file and then compresses it and also uploads it to google drive.</p>
<h4>BASH</h4>
<pre><code class="html hljs xml">mysqldump -u mysqluser -pMySqlPassword $1 > ~/backup/$1.sql<br />tar -czvf ~/backup/$1sql.tar.gz ~/backup/$1.sql<br />rclone copy ~/backup/$1_sql.tar.gz gdrive:Backup/nerd.kruxor.com</code></pre>
<p>x</p>
