Simple backups using Rsync with SSH

posted Originally published at drowr.vercel.app 1 min read

This post explains how to SSH with Rsync to make backup of your system efficiently and securely.

The only requisite to start here is an access to SSH somewhere.

Create your ssh keys

Here, i just create a keypair called “rsync”, ssh will create a private and a public key.

ssh-keygen -t ed25519 -o -a 100 -f ~/.ssh/rsync

After, just send the public key to the server with scp targeting your server.

 scp ~/.ssh/rsync.pub backup@SERVER

Create a backup script

Create a shell script named rsync-backup.sh with the following content:

#/usr/bin/env sh

set -o errexit

# All variables
SERVER="192.168.1.11"
BACKUP_FILE="/tmp/backup.filter"

# More efficient than playing with --include,--exclude
cat << EOF > "$BACKUP_FILE"
# Include patterns
+ /documents/***
+ /Downloads/***
+ /downloads/***
+ /images/***
+ /musics/***

# Exclude everything else
- /**
EOF

# And finally the rsync command
rsync -avP --delete -e "ssh -i $HOME/.ssh/rsync" \
    --bwlimit=400 \
    --filter="merge $BACKUP_FILE" \
    "$HOME/" "backup@${SERVER}:backups/"

The script here will backup your $HOME with only certain directory in the “include pattern list”. Just ensure the server address is correct.

I also limit the bandwidth because it break my wifi card (bad hardware…)

Execute the script

Just give permission and launch the script.

 chmod u+x rsync-backup.sh
./rsync-backup.sh

Conclusion

Using SSH with Rsync is an efficient and secure method for backing up your system. By generating SSH keys and creating a simple shell script, you can automate the backup process, ensuring that your important files are safely stored on a remote server.

Adjusting settings like bandwidth limitation can help optimize performance, especially on networks with limited resources. This approach not only provides a reliable backup solution but also enhances data security through encrypted connections.

1 Comment

0 votes

More Posts

The Audit Trail of Things: Using Hashgraph as a Digital Caliper for Provenance

Ken W. Algerverified - Apr 28

How to Expose Localhost to the Public Using Nginx and SSH Tunnels

Ganesh Kumar - May 3

How does SSH work and how can it be set up?

Ganesh Kumar - Apr 29

The Quest Continues: Porting the Word Game With AsyncSSH

kitfu10 - May 4, 2025

DevLog 20251214: Yet Another Shell Script – Keeping Build Automation Simple with EasyShell

Methodox - May 4
chevron_left

Related Jobs

View all jobs →

Commenters (This Week)

9 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!