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 Quest Continues: Porting the Word Game With AsyncSSH

kitfu10 - May 4, 2025

Tuesday Coding Tip 02 - Template with type-specific API

Jakub Neruda - Mar 10

Your WordPress Site Will Fail. Be Ready.

Serhii-Kolodych - Dec 18, 2025

Autopilot - the Final: From Localhost to the Cloud with GitHub Actions and CI/CD

Datalaria - Feb 16

How I Automated Git Commands Using Batch Scripting

Ifeanyi - Apr 9, 2025
chevron_left

Related Jobs

View all jobs →

Commenters (This Week)

3 comments
2 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!