Backup to Dropbox in Ubuntu
12-18-2015, 07:10 AM
(This post was last modified: 12-18-2015, 08:56 AM by pinguy.)
To Backup files to Dropbox run:
Follow the on prompt commands because you will need to create a Dropbox API.
For tips on how to use the script see: https://github.com/andreafabrizi/Dropbox-Uploader
Once complete you can make a cron job to backup the whole site to Dropbox.
Example:
This is to backup the whole site to Dropbox once a Month.
F3 will save the file and Ctrl+X will exit nano.
Next set permissions and make it executable.
To backup databases to Dropbox daily run:
F3 will save the file and Ctrl+X will exit nano.
Next set permissions and make it executable.
What's great about doing this is Dropbox keeps backups of the files for up to 30 days (trust me this has saved my ass more then once). So it makes it pretty easy to roll back to an older backup of the database.
Also if you use the desktop client you will have synced local copies of the site and databases on your PC.
As my site is just under 2GB (zipped) I have no issues using the free version of Dropbox (free version offers up to 16 GB). So I do find this an elegant free solution to keep backups.
Code:
wget -O dropbox_uploader.sh https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh
chmod a+rx dropbox_uploader.sh
sudo mv dropbox_uploader.sh /usr/local/bin/dropbox_uploader
sudo chown root:root /usr/local/bin/dropbox_uploader
dropbox_uploader
Follow the on prompt commands because you will need to create a Dropbox API.
For tips on how to use the script see: https://github.com/andreafabrizi/Dropbox-Uploader
Once complete you can make a cron job to backup the whole site to Dropbox.
Example:
This is to backup the whole site to Dropbox once a Month.
Code:
nano /etc/cron.monthly/backup
Code:
#!/bin/bash
rm -rf /var/sentora/hostdata/zadmin/backup.zip
cd /var/sentora/hostdata/zadmin/
zip -r backup.zip public_html
dropbox_uploader delete /backup.zip
dropbox_uploader upload /var/sentora/hostdata/zadmin/backup.zip /backup.zip
exit 0
F3 will save the file and Ctrl+X will exit nano.
Next set permissions and make it executable.
Code:
sudo chmod +x /etc/cron.monthly/backup
sudo chmod 755 /etc/cron.monthly/backup
To backup databases to Dropbox daily run:
Code:
nano /etc/cron.daily/database
Code:
#!/bin/bash
mkdir -p /var/sentora/hostdata/zadmin/database
mysql -u root -p*PASSWORD* -e "FLUSH TABLES WITH READ LOCK;"
mysqlcheck --auto-repair -Aos -u root -p*PASSWORD*
mysqldump -u *USER* -p*PASSWORD* *DATABASE_NAME* > /var/sentora/hostdata/zadmin/database/*DATABASE_SAVE*.sql
*Repeat the above line for each database*
mysql -u root -p*PASSWORD* -e "UNLOCK TABLES;"
rm -rf /var/sentora/hostdata/zadmin/database.zip
cd /var/sentora/hostdata/zadmin/
zip -r database.zip database
rm -rf /var/sentora/hostdata/zadmin/database
dropbox_uploader delete /database.zip
dropbox_uploader upload /var/sentora/hostdata/zadmin/database.zip /database.zip
exit 0
F3 will save the file and Ctrl+X will exit nano.
Next set permissions and make it executable.
Code:
sudo chmod +x /etc/cron.daily/database
sudo chmod 755 /etc/cron.daily/database
What's great about doing this is Dropbox keeps backups of the files for up to 30 days (trust me this has saved my ass more then once). So it makes it pretty easy to roll back to an older backup of the database.
Also if you use the desktop client you will have synced local copies of the site and databases on your PC.
As my site is just under 2GB (zipped) I have no issues using the free version of Dropbox (free version offers up to 16 GB). So I do find this an elegant free solution to keep backups.