RClone Backup with Cronjob
Here’s a quick and straightforward method for backing up your data to the cloud.
warning
Instructions are based on a Linux bash shell, so they may vary if you use PowerShell or a different shell.
Installation
To install rclone on your machine, run:
sudo -v ; curl https://rclone.org/install.sh | sudo bash
This command downloads the install.sh script, runs it with elevated privileges, and automatically updates your system path with rclone.
Setup Remote
- Run
rclone config. - Create a new remote configuration.
- Assign a name for your remote. (For example, use “MY_GOOGLE_DRIVE_REMOTE”.)
- When prompted, provide the Google Drive remote ID.
- Skip client ID and client secret by pressing Enter.
- Set the scope to “1” for full access.
- Leave advanced configuration settings unchanged unless you have specific requirements.
- If using SSH, select “n” for web-browser authentication and follow the prompt to authorize rclone.
- Once authorized, you can verify your Google Drive files by running:
rclone ls MY_GOOGLE_DRIVE_REMOTE:
Copy Files from Source to Remote
rclone copy ./backup MY_GOOGLE_DRIVE_REMOTE: -v
This command copies all files from the local “backup” directory to your remote storage.
Cronjob
Open your crontab by running:
crontab -e
Add the following new line to schedule the backup to run daily at midnight:
0 0 * * * /usr/bin/rclone copy ./backup MY_GOOGLE_DRIVE_REMOTE: -v >> /var/log/backup.txt 2>&1
This line executes the rclone copy command at 00:00 each day and writes the backup log to “backup.txt”.