Automatic Backup On Windows Server And Linux

Marzuki
4 min readFeb 9, 2021

Hi everyone, this is my first writing, because I often lose files on windows and linux servers so I decided to write this, maybe you guys also experience the same thing.

here I use google drive to back up my two servers. so you need a google drive account with unlimited capacity.

Windows Server

for windows server is actually very easy, you just need to download drive from https://www.google.com/drive/download/. then install and login to your google account. select the folder to be backed up and done. it will also detect automatic changes in folder.

Linux Server

for linux you can use rclone

instalation:

1.curl https://rclone.org/install.sh | sudo bash

2.rclone config

3.select new remote, before I made it with the name ubuntu

4.in the name enter up to you for example backup-ubuntu

5.in this step you can choose number 15 because I will use google drive. and yes the scope section select 1 to provide full access to Google Drive

6.at the root id folder just press enter. edit advanced config select N. remote config Y

7.will appear auth url for google account, copy and paste into browser.
here I use vps. So so that my local IP can be accessed by the public, I use ngrok. ./ngrok http (port) then access the ngrok url in the browser and don’t forget to add the path behind the ngrok url. after that auth to your account and done.

bash script for backup, (adjust to the folder to be backed up) here my files are in the root folder.

use crontab for automatic backup

chmod +x backup.sh

0 12 * * * /dir/backup.sh

Here’s what the parameters mean:

copy: Copy the files from the local computer to the remote storage, skipping over files that are already present on the remote storage.

–update: Skip any files that are on the remote storage that have a modified time that is newer than the file on the local computer.

–verbose: Gives information about every file that is transferred.

–transfers 30: This sets the number of files to copy in parallel.

–checkers 8: How many “checkers” to run in parallel. Checkers monitor the transfers that are in progress.,

–contimeout 60s: The connection timeout. It sets the time that rclone will try to make a connection to the remote storage.

–timeout 300s: If a transfer becomes idle for this amount of time, it is considered broken and is disconnected.

–retries 3: If there are this many errors, the entire copy action will be restarted.

–low-level-retries 10: A low-level retry tries to repeat one failing operation, such as a single HTTP request. This value sets the limit for the number of retries.

–stats 1s: rclone can provide statistics on the transferred files. This sets the frequency of update of the statistics to one second.

“/root/folder-in-your-vps”: The local directory to we’re going to copy to the remote storage.

“ubuntu-backup:FOLDERGDRIVE/foldervps”: The destination directory in the remote storage. Note the use of “ubuntu-backup”, which is the name we gave to this remote connection during the the rclone config sequence. Also note the colon “:” that is used as a separator between the remote storage name and the directory name. Subdirectories are separated by the usual “/” forward slash. If the destination directory does not exist, it will be created.

so, hope this is useful and sorry for the bad english.

Thanks.

--

--