Today we will talk about transferring backups of your sites hosted in VestaCP to Google Drive. After all, we all know that storing backups in only one place is a bad idea. Server failure, hackings, administrative errors can lead to irreversible loss of data, and no one wants to lose their brainchild, and for this, the presence of a fresh backup in a safe distant place adds confidence in the future.
Must Read:
So for this purpose, we are going to use google-drive-ocamlfuse. It is a FUSE file system for Google Drive, written in OCaml. It lets you mount your Google Drive on Linux.
Install google-drive-ocamlfuse on your Linux server with VestaCP Installed. With this program, we will connect Google Drive to our server and will be able to manage files directly from Linux CLI.
sudo add-apt-repository ppa: alessandro-strada / ppa sudo apt-get update sudo apt-get install google-drive-ocamlfuse
Step 2: Once you have successfully installed google-drive-ocamlfuse on your server the next step is to authorize and access your Google Drive Account.
google-drive-ocamlfuse -headless -label me -id IDENTIFIER-secret SECRET
Please, open the following URL in a web browser: https: //accounts.google.com / ...
mkdir / google_dir google-drive-ocamlfuse -label me /google_dir
In this step, we will automate the transfer of backup archive to Google drive by scheduling cron tasks.
1. First, create a folder inside /google_dir folder named backups, this will be used as temporary storage until the transfer process completes.
sudo mkdir /google_dir/backup/
2. Enter the below command (a choice of text editors may appear, I advise you to choose nano or vim which you have installed):
crontab -e
3. Add the following line to the end of the cron file:
44 2 * * * sudo cp -R -n /backup/*.tar /google_dir/backup/
Now you can configure the archive transfer schedule by modifying the above line with your cron execution time. For example in my scenario at 2:44, by server time, on behalf of the administrator, files matching the * .tar mask will be copied to the “google_dir/backup/” folder, files that are already found in the target folder will not be copied. If you have many users, and you need only one backup, then it would be wise to change the file mask to admin *.tar.
Now make sure that VestaCP backups are turned on as this will only use those backups created by VestaCP in backups and will transfer them in your Google Drive folder as per your cron schedule.
Note: You can also paste the above command in cron settings provided by VestaCP.
In this process, you can configure on how much backup cycle or for days your backup will retain on Google drive and after that, it will automatically delete older archives.
sudo nano /etc/delete-backup.sh
2. Make the file executable.
sudo chmod ugo + x /etc/delete-backup.sh
3. Schedule the automatic execution. Add the below code inside the file that you created.
10 2 * * * sudo /etc/delete-backup.sh /google_dir/backup/ * tar 7
The above command will be executed at 2:10 on server time, on behalf of the administrator, the files in the folder “/google_dir/backup/” matching the mask “* tar” will be deleted leaving the 7 of the most recent ones untouched.
That’s all, the above steps will automate your Backups to Google Drive. If you face any problem following the steps or need any help just leave your queries in the comments below.