Upload Vesta user backups to Dropbox automatically daily
Posted: Fri Mar 17, 2017 2:49 pm
I have setup my Centos 7 server to send the Vesta backups of all my websites (users) to Dropbox automatically every day (after Vesta has run the backup job). In case it helps anyone, here is how.
Configure Dropbox uploader
Optional: Send a single file to Dropbox as a test (replace with your backup filename).
Schedule the backups to go to Dropbox daily
Make this new file:
Add this to the file, then save it (type Esc, :wq):
Note: The backup file that is uploaded to Dropbox has the date removed from its filename so that every day, the new backup will overwrite the previous backup in Dropbox. This way you don't get an accumulation of backups (e.g. admin.2017-03-17.tar, admin.2017-03-18.tar, etc...) and always only have one backup file for each user (e.g. admin.tar) in Dropbox. Using Dropbox's file version history, you can access older backups of that user. The backups on the server are unchanged (they are not renamed, and they are kept for two days as per Vesta's normal behaviour).
Optional: Run it once as a test (your backups folder must have today's backups in it).
Verify what time Vesta does its daily backups:
Edit crontab:
Add this line to crontab so your backups are sent every morning at 3:45am (or any other time you want, just make sure it is at least 30 minutes after Vesta does the backups). Change the email address at the end to whatever address you wish to get the emailed report.
Optional: You can view the log here (but this will also get emailed to as per the previous step).
That is all, your backups will now be sent to Dropbox daily at the time you specified in crontab, and you will get an email report with the results.
I have successfully used this for files up to 10 Gb in size, and I think it should work fine for even larger. You can read more about how the Dropbox Uploader script does this, and other options it offers, here: https://github.com/andreafabrizi/Dropbox-Uploader
Configure Dropbox uploader
- Go here: https://www.dropbox.com/developers/apps
- Create a new Dropbox app and give it access to a new folder in the Apps directory (e.g. server_backups)
- Generate and copy your access token
- On your server, enter these commands (make a directory, navigate to it, download the dropbox upload bash script dropbox_uploader.sh, give it execution permissions, execute it) and paste your token when prompted to.
Code: Select all
cd /
mkdir dropbox
cd dropbox
curl "https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh" -o dropbox_uploader.sh
chmod 755 dropbox_uploader.sh
./dropbox_uploader.sh
Code: Select all
/dropbox/dropbox_uploader.sh upload "/home/backup/admin.2017-03-17.tar" /
Schedule the backups to go to Dropbox daily
Make this new file:
Code: Select all
vi /usr/local/bin/send_site_backup_files_to_dropbox.sh
Code: Select all
#!/bin/bash
#Save current date as YYYY-MM-DD to a variable
DATE=$(date +"%Y-%m-%d")
#Loop through each file in the backup folder whose name has the current date
for X in /home/backup/*$DATE*; do
#X is the filename with path. Remove path to get just the filename.
NAME_NO_PATH=${X##*/}
#Remove the date from the name (removes all text between the periods)
NEW_NAME="${NAME_NO_PATH%%.*}.${NAME_NO_PATH##*.}"
#Copy the file to tmp with the new non-dated name
cp $X /tmp/$NEW_NAME
#Send it to Dropbox
/dropbox/dropbox_uploader.sh -f /root/.dropbox_uploader upload "/tmp/$NEW_NAME" /
#Delete the file from tmp
rm -rf /tmp/$NEW_NAME
done
Optional: Run it once as a test (your backups folder must have today's backups in it).
Code: Select all
sh /usr/local/bin/send_site_backup_files_to_dropbox.sh
- Log into Vesta as admin
- Click Cron
- Find “sudo /usr/local/vesta/bin/v-backup-users” and click edit
- Verify what time Vesta does backups (change the time if desired)
Code: Select all
yum install moreutils
Code: Select all
crontab -e
Code: Select all
45 03 * * * sh /usr/local/bin/send_site_backup_files_to_dropbox.sh | ts "[\%Y-\%m-\%d \%H:\%M:\%S]" 2>&1 | tee /var/log/send_backups_to_dropbox.log | mailx -s "Report for Vesta backup files sent to Dropbox" [email protected]
Code: Select all
cat /var/log/send_backups_to_dropbox.log
I have successfully used this for files up to 10 Gb in size, and I think it should work fine for even larger. You can read more about how the Dropbox Uploader script does this, and other options it offers, here: https://github.com/andreafabrizi/Dropbox-Uploader