The backup.sh
script helps you automatically save a folder you choose to both your computer and a remote storage service using rclone
. It also has features to remove old backups and to notify you when the backup is done successfully.
- Clone this repository
git clone https://github.com/dhruvmistry2000/Backup-Script.git
- Install zip on you server. For Ubuntu Server
sudo apt install -y zip
For RHEL Server
sudo yum install -y zip
For Fedora Server
sudo dnf install -y zip
- Before running the script, you need to configure the following variables at the top of the script:
SOURCE_DIR
: The directory you want to back up.BACKUP_DIR
: The local directory where backups will be stored.REMOTE_NAME
: The name of the remote storage configured inrclone
.REMOTE_DIR
: The directory on the remote storage where backups will be stored.DAYS_TO_KEEP
: The number of days to keep local backups before they are deleted (By default I have set the value to 7).
- In the send_notification function backup.sh file change the ip address to the machines ip address.
- For backend configuration refer to Readme.md.
Rclone is a command-line program that enables users to manage and synchronize files and directories between various cloud storage services and local file systems. It supports a wide range of cloud providers, including Google Drive, Dropbox, OneDrive, Amazon S3, and many others.
- Install rclone using the following command in linux.
sudo -v ; curl https://rclone.org/install.sh | sudo bash
- Check if rclone is installed or not.
rclone -v
If not use the first command again.
- Now configure the rclone remote using the following command.
rclone config
-
Now we need to configure a new remote drive to press "n" and press "ENTER".
-
Give your desired name. In my configuration I haved named it "gdrive" and press "ENTER".
-
Now choose the desired platfrom on which you want the remote backup to store. Here I have used Google Drive, so will give give "20" and press "ENTER".
-
This will ask for client_id and client_secret we can leave them empty and press "ENTER".
-
It will now ask for what kind of scope we want to give to. Scope means what kind of permission we want this pc to give to the remote drive. I want to give "Full access all files, excluding Application Data Folder" permission, so will press 1 and press "ENTER".
-
This will ask for service_account_file, we can leave it empty and press "ENTER".
-
If we want to do more advance configuration the press "y" and press "ENTER". I don't want to do advance configuration so I will press "ENTER".
-
Now if the machine has a web-browser then press "y" and login into the account we want to save our remote backups.If not then it will give a command you will need to execute on a machine that has a web-browser and paste the command and then login into the account.Now in the command line you will get a key which you need to paste into the config_token.
-
Now if you want to configure this as a shared drive then press "y". I don't want to so I will press "n" and press "ENTER".
-
Now it will ask if we want to keep the configured file, press "y" and then "ENTER" and then if you want to configure more remote drive then follow the steps again if not then press "q" and "ENTER".
-
To check if the configuration is saved or not use the following command.
rclone config show
This will show the configuration which we have done.
- Now to test if the remote drive is configured or not use the command.This command will the files what are in the remote drive.Here / means the root.
rclone ls <remote_drive_name>:/
- Now if this works properly make a new folder in the remote drive and then give the required values in backup.sh