How to Backup Your Raspberry Pi to the Cloud with rclone
Backing up your Raspberry Pi is crucial to prevent data loss. Among the various automated tools I’ve tested, rclone is the most versatile for cloud backups. It’s compatible with nearly all major cloud providers and runs quietly in the background once set up. I’ll guide you through the installation process on your Raspberry Pi.
Rclone is a command-line tool that syncs files from the Raspberry Pi to cloud services like Google Drive, Dropbox, and OneDrive. It’s reliable, lightweight, and easy to use.
We’ll walk through installing rclone, linking it to your cloud account, building a simple backup script, and scheduling automatic backups. Even if you’ve never used a tool like this before, don’t worry, you’ll have a solid cloud backup by the end.
If you’re new to Raspberry Pi or Linux, I’ve got something that can help you right away!
Download my free Linux commands cheat sheet – it’s a quick reference guide with all the essential commands you’ll need to get things done on your Raspberry Pi. Click here to get it for free!
How to Install rclone on Raspberry Pi
Installing rclone is quite simple. There are multiple options, including building from source or downloading pre-built binaries. You can find all installation options on their official website.
The simplest method is to use the install script.
You can download it from your terminal using this command:sudo -v ; curl https://rclone.org/install.sh | sudo bash

You will know the installation is successful if you see this message once the script has completed execution:
Read next: 15 Easy Projects for Raspberry Pi Beginners

Note: Make sure your system is up-to-date before running this script. You can update your system by using these commands:sudo apt updatesudo apt upgrade
Once installed, you can verify the installation using the command:rclone version

As you can see from the output of this command, rclone is successfully installed on your Raspberry Pi. Now we can start configuring it to sync with our preferred cloud service.
Members get an ad-free version of every guide, plus exclusive project support.
Join the Community | Sign In
Configuring rclone to Sync With Cloud Service
After installing rclone on your device, you can begin the configuration process. Rclone can sync with more than 70 cloud storage services, allowing you to choose your preferred option. For this tutorial, we will focus on using Google Drive.
To configure rclone to sync with any cloud service, follow these steps:
Download the free PDF, keep it open, and stop wasting time on Google.
Download now
- Enter the following command to start the configuration process:
rclone config
- Type n and press Enter.
- Type a name for your remote and press Enter (You can use any name that you will use to reference this remote drive):

- Enter the S No corresponding to the cloud storage service of your choice (20 is for Google Drive) and press Enter:

- Enter your Client ID (Google Drive OAuth):

If you’ve never done this, this tutorial from rclone might help with the steps in the Google API Console. - Enter your Client Secret:

- Next, select the scope of authorization that rclone will have over your Google Drive:

- Leave the next prompt empty and press Enter.

- Type n and press Enter.

- Type y and press Enter.

- You will be taken to the Google Sign In screen on your web browser:

- Sign in to your Google account and give permissions to rclone:

- Type n and press Enter at the following prompt:

- Type y and press Enter to complete the remote creation process:

- Type q and press Enter to leave the rclone configuration menu:

That’s it; we have successfully configured our rclone to sync with Google Drive. You can test this setup using the command:rclone lsd remote:

The output from the above command shall display all the directories inside your Google Drive folder.
You can also test by sharing a test file (You will need to create a test file first), for example, you can use this command:rclone copy test.txt remote:

You can then use the browser to browse to your Google Drive and verify that the test.txt file has been uploaded.

Once you have verified that your rclone setup is working, we can start making backups of your Raspberry Pi.
Creating a Cloud Backup Script
As you can see, copying files to your remote cloud storage service is as simple as running a copy or sync command. However, to schedule backups to Google Drive, it is recommended that you create a custom script.
Before creating our script, I recommend creating a dedicated folder in your Google Drive where backups will be saved. I made a folder named “PiBackup” in my Google Drive.

Next, create a bash script as shown below:
#!/bin/bash
# ==== Configuration ====
REMOTE_NAME="GDrive"
DESTINATION_BASE="PiBackup"
SOURCES=( "/home/pat/Documents" "/home/pat/Projects" )
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")
DESTINATION="$REMOTE_NAME:$DESTINATION_BASE/$TIMESTAMP"
FILELIST="/tmp/rclone_files.txt"
# =======================
# Clear previous file list
> "$FILELIST"
echo "Starting backup to: $DESTINATION"
# Collect all files from each source folder
for SRC in "${SOURCES[@]}"; do
if [ -d "$SRC" ]; then
find "$SRC" -type f >> "$FILELIST"
echo "Added files from: $SRC"
else
echo "Warning: $SRC is not a valid folder. Skipping."
fi
done
# Run rclone to copy the files while preserving full paths
rclone copy / "$DESTINATION" \
--files-from "$FILELIST" \
--create-empty-src-dirs \
--copy-links \
--progress
echo "Backup finished!"
If you are copying the above script, make sure you change the Configuration section as per your setup.
Once created, you will need to make the script executable by using the command:sudo chmod +x your_script_name.sh
Download the free PDF, keep it open, and stop wasting time on Google.
Download now

Now you can execute the script to create a timestamped backup to your Google Drive:./your_script_name.sh

You can log in to your Google Drive folder using any browser to verify that a new folder has been created in your PiBackup folder that contains all the backed-up files.

You can look inside this folder to find files of all the folders mentioned as the SOURCES in the bash script.
Quick note: If you find it hard to remember all these commands, I’ve put them all on a one-page cheat sheet. You can download it for free here so you have it handy whenever you're working on a project.
Automating With Crontab
While we can continue to use the previously created script every time to make a manual backup, it would be much more efficient if we could schedule the script to run automatically. We can do this using crontab.
To automate using crontab, follow these steps:
You might also like: The 5 fastest web browsers for Raspberry Pi — tested and ranked!
- Open the crontab editor using the command:
crontab -e
- Make the following entry in the text file:

We have configured this backup script to run at 2 AM every day. You can configure it based on your preference. To learn how to configure crontab tasks, follow this tutorial on scheduling tasks with crontab.
Now your Raspberry Pi is configured to automatically create a backup every day at 2 AM to your Google Drive, including a date and time stamp for the backup.
Restoring a Backup From the Cloud
Once we have created our backups, the next logical step is to learn how to restore them if necessary. Restoring backups with rclone is straightforward and can be done with a single command.
While you can write a bash script for restoration, manually restoring is generally a more straightforward and effective choice for basic restoration tasks.
Download the free PDF, keep it open, and stop wasting time on Google.
Download now
To restore your system using backups from Google Drive using rclone, follow these steps:
- List all the backups that you have created using the command:
rclone lsd remote:backup_folder_name
- As you can see, we have two different backups in our cloud storage.
- Use this command to restore using one of the backups:
rclone copy remote:backup_folder_name/backup_name/ / --copy-links --create-empty-src-dirs --progress
This approach will restore all files from your Google Drive to your local storage and overwrite any existing files.
If, alternatively, you only want to restore selective folders from your backup, you can do that as well by specifying the exact folders in the source and destination as shown below:

You can also use the sync command instead of copy. The sync command would also delete any new files in the target directory to make it exactly as it was at the time of the backup. To use the sync command, first run the restore in dry run mode using the command:rclone sync remote:backup_folder_name/backup_name/path_to_source/ /path_to_destination/ --copy-links --create-empty-src-dirs --progress --dry-run

The output shows that one newly created file will be deleted when this restore is run. If you are sure you want to go ahead with this restore, you can run the command without the– dry-run flag.

Note: Be careful not to use the sync option if trying to restore the complete snapshot to the root directory. This flag will delete all OS files we chose not to back up.
Using these basic commands, you can also make your custom restore script; however, for most use cases, that is not required.
Want to connect with other Raspberry Pi fans? Join the RaspberryTips Community. Ask questions, share your projects, and learn from each other. Join now.
Taking It One Step Further
While setting up a basic backup and learning how to restore it using rclone is sufficient for most users, there are a few advanced options and considerations that I would like to discuss as well.
These are options possible using rclone, but are not necessarily required to set up your backup using rclone.
Encryption
Suppose you are looking to back up and restore sensitive data and do not trust your cloud service provider to handle your privacy with sensitivity. In that case, rclone offers the option to encrypt the data it shares with your cloud service provider.
Download the free PDF, keep it open, and stop wasting time on Google.
Download now
To enable encryption on your backup directory, follow these steps:
- Run the rclone configuration menu using the command:
rclone config
- Type n and press Enter.
- Type a new name for the encrypted remote and press Enter:

- Enter 14 (for crypt) and press Enter:

- Enter the folder name on your Google Drive that will contain the encrypted files (For this tutorial, I created a new folder on my Google Drive named “EncryptedPiBackup”:

- Enter 1 (standard) and press Enter:

- Enter 1 (true) and press Enter:

- Enter y and press Enter:

- Enter a secure password and press Enter:

- Type y and press Enter:

- Follow the prompts to enter another password (different from the first one).
- Type n and press Enter:

- Follow the prompts to complete the configuration.

- Open your backup script in a text editor and change the REMOTE_NAME variable to the name of the new encrypted backup remote:

That’s it; we have configured our rclone to make encrypted backups to the cloud storage. You manually run the script to create a backup. Once the backup is created, navigate to your cloud storage using any browser to view the files:

As you can see, the names and contents of the files and folders cannot be deciphered when accessing the backup from the browser.
However, when you access the same through your rclone, you can easily access the names and contents of all the files and folders in your backup directory:

All the data saved in your backup is now end-to-end encrypted. Neither your cloud storage service provider nor anyone else on the internet can read the contents of your backup. For anyone to access this data, they will need the two passwords that you defined.
Encryption can be a great way to protect your sensitive data, or if you don’t trust your cloud storage service provider.
Backup & Restore Script Ideas
While the backup script should be sufficient for most users, since it is a bash script, there is a ton of flexibility that can be used to improve your backup script.
A few ideas that you can use to improve your backup script are listed below:
- Add Email or Push Notifications: You can use applications like Mail, msmtp, or Pushbullet to notify the user when a backup is completed or if any errors occur.
echo "Backup completed!" | mail -s "Raspberry Pi Backup Success" [email protected] - Use Exclusion Filters: You can use exclusion filters to exclude certain file types or folders when creating your backups. For this, you can use the –exclude or –exclude-from flags with a pattern list to achieve this functionality:
rclone copy / "$DESTINATION" --files-from "$FILELIST" --exclude-from "/home/pi/exclude.txt" - Backup Rotation & Cleanup: If you are concerned about the available space from your cloud storage service provider, you can use the lsd and purge functions of rclone to retain only a predefined number of backups and remove any older backups.
rclone lsd gdrive:PiBackup | sort | head -n -5 | while read -r line; dofolder=$(echo $line | awk '{print $NF}')rclone purge gdrive:PiBackup/$folderdone - Compression Before Upload: To further economize space consumption, you can compress files that you intend to back up before uploading them:
zip -r /tmp/backup.zip /home/pi/Documentsrclone copy /tmp/backup.zip gdrive:PiBackup/$TIMESTAMP/ - Multi-Cloud Redundancy: Using rclone, you can configure more than one cloud storage service provider at a time. Therefore, you can back up to more than one service provider to improve redundancy.
- Make a Matching Restore Script: You can make a matching restore Bash script that automatically detects the latest backup and restores to that:
LATEST=$(rclone lsd gdrive:PiBackup | sort | tail -n 1 | awk '{print $NF}')rclone copy gdrive:PiBackup/$LATEST / --copy-links --create-empty-src-dirs
With just a bit of setup, rclone turns your Raspberry Pi into a self-reliant system with automatic, cloud-based backups you can count on.
If you’d like to learn about other backup methods, we also have a guide here: 5 Best Ways to Back Up Your Raspberry Pi (With Pros & Cons)
Whether you keep things simple or expand with encryption and scripts, you’re in complete control of your data’s safety.
Whenever you’re ready, here are other ways I can help you:
Test Your Raspberry Pi Level (Free): Not sure why everything takes so long on your Raspberry Pi? Take this free 3-minute assessment and see what’s causing the problems.
The RaspberryTips Community: Need help or want to discuss your Raspberry Pi projects with others who actually get it? Join the RaspberryTips Community and get access to private forums, exclusive lessons, and direct help.
Master your Raspberry Pi in 30 days: If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.
Master Python on Raspberry Pi: Create, understand, and improve any Python script for your Raspberry Pi. Learn the essentials step-by-step without losing time understanding useless concepts.
You can also find all my recommendations for tools and hardware on this page.
