MadPopo Best WordPress Hosting Solution

Need Help ?  Call Us 24/7 : +91 7039 003 001

Linux Server Backup Using Rclone

In this article, we’ll guide you through the process of establishing both manual and scheduled backups for any Linux server, utilizing rclone to store data in S3 Object Storage.

This tutorial is applicable for backing up any Linux server, whether it’s a Dedicated Server, VPS, or VDS. The provided commands have been tested on Ubuntu 18.04 (64 Bit), Ubuntu 20.04 (64 Bit), Debian 9, and Debian 10. Some adjustments may be necessary for other distributions like CentOS.

To execute the commands outlined in this guide, root access is required. Log in as root or elevate your privileges by typing:

 sudo -i 

Initial Linux Server Backup Configuration 

1. Getting S3 Credentials to Store the Backup

In this tutorial, we’ll employ Madpopo Object Storage as our backup storage, assuming you have an active Object Storage subscription. Ensure you have the necessary credentials, including access_key, secret_key, and URL, which can be found in the Object Storage section of your CCP for Madpopo

S3 Object Storage credentials in CCP

2. How to Create a Backup File on Linux Server

Initially, we need to install the most recent version of rclone.

curl | sudo bash 

Using the subsequent command, we’ll generate a backup of the current user and store the backup file with the date in the /opt/backup/ directory.

mkdir /opt/backup/ 
cd /opt/backup && tar -cvzf backup-$(date +%d.%m.%Y).tar.gz --directory=/ --exclude=lost+found --exclude=dev/* --exclude=proc/* --exclude=run/* --exclude=sys/* --exclude=tmp/* --exclude=mnt/* --exclude=media/* --exclude=opt/backup/* . 

The command breakdown is as follows:

  • tar: This command is used to create an archive of our data.
  • c: Stands for “create” and is used to create a new archive.
  • v: Represents “verbose” mode, providing detailed output during the process.
  • z: Indicates the use of gzip compression for the archive.
  • f: Denotes “file” and is followed by the name and location of the archive. It must be the last option passed, as everything after f is treated as a file path.
  • /path/filename.tar.gz: Specifies the path where the archive will be written.

The exclusion of certain directories is intentional to conserve storage space or to avoid including large unwanted files, such as those in the temporary directory.

3. Configuring Rclone on a Linux Server

We presume that the files and folders you intend to back up are stored in the directory /opt/backup/.

Follow the Rclone setup instructions provided in our product documentation here. Once configured, you can proceed with performing the Linux server backup using Rclone.

4. Transferring Your Backup File from Linux Server to S3

I’ve named my object store “eu2,” and my designated backup folder is “backup.” To proceed, we must now create a bucket where all the files will be stored.

rclone mkdir eu2:backup 

Once you’ve successfully completed all the steps outlined in the “Initial Configuration” section above, execute the following command to transfer the files from /opt/backup to your designated destination bucket in Object Storage.

rclone copy -P /opt/backup eu2:backup/server1 

Copy all data  

rclone move –P /opt/backup eu2:bucketname/server1 

Move will delete files after transfer 

rclone sync –P /opt/backup eu2:bucketname/server1 

Sync updates files on remote storage

5. Scheduling Rclone Backups

Upon completing the “Initial Configuration” section above, you can initiate scheduled backups to be generated automatically.

Initially, we need to create the script file:

And add this to the script :


cd /opt/backup && tar -cvzf backup-$(date +%d.%m.%Y).tar.gz --directory=/ --exclude=lost+found --exclude=dev/* --exclude=proc/* --exclude=run/* --exclude=sys/* --exclude=tmp/* --exclude=mnt/* --exclude=media/* --exclude=opt/backup/* .

/usr/bin/rclone sync -P --update --verbose --transfers 30 --log-file=/var/log/upload.log "/opt/backup" "eu2:backup/"

Now we make the file executable

sudo chmod +x /var/

Now we have to add our script to cron

sudo crontab –e


0 2 * * * /var/

In this instance, the file /var/ is invoked every day at 02:00. For further insights into diverse backup strategies, refer to this article.

Feel free to adjust the time and date according to your preferences. If you’re unfamiliar with cron, a crontab generator is available here to assist you.

This straightforward approach ensures the integrity and safety of your data. It’s highly recommended to regularly backup your Linux servers using a tool like rclone.

6. Restore Data with Rclone

rclone copy -P eu2:backup/server1 /opt/backup

To download your backup, you need to switch source and destination parameters, specifying the particular backup you wish to retrieve

Additional Information:

For more details on flags and configuration options, refer to the official documentation.

In certain situations, it may be necessary to add –s3-chunk-size 200M to your script, especially if your upload speed is exceptionally slow.

Sanyog Shelar

passionate about programming and system architecture design, and he uses his deep knowledge to help clients achieve their goals. He also shares his expertise on various cybersecurity issues and offers practical advice on how to protect against common threats. In addition to his technical skills, Sanyog is an expert in server management and is able to provide expert advice on how to manage web applications at the server level.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.