Remote Server Rsync Backup Replication Shell Script

You need to setup password less login using ssh keys; refer to following tutorials:
+ Howto Linux / UNIX setup SSH with DSA public key authentication (password less login)

+ SSH Public key based authentication – Howto

# Remote Server Rsync backup Replication Shell Script 
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit for more information.
# ------------------------------------------------------------------------- 
# Local dir location
# remote ssh server
# user
# server IP / host
#remote dir to backup
rsync --exclude '*access.log*' --exclude '*error.log*' -avz -e 'ssh ' ${SSHUER}@${SSHSERVER}:${SSHBACKUPROOT} ${LOCALBAKPOINT}${LOCALBAKDIR}
# log if backup failed or not to /var/log/messages file
[ $? -eq 0 ] && logger 'RSYNC BACKUP : Done' || logger 'RSYNC BACKUP : FAILED!'
# Replicate backup to /disk1 and /disk2
# You can also use format user@host:/path
# refer to rsync man page
DST="/disk1/remote /disk2/remote"
for d in $DST
 [ ! -d $d ] && mkdir -p $d || :
 rsync -avr $SRC $d
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source, and DevOps topics via:
Category List of Unix and Linux commands
Disk space analyzers ncdu pydf
File Management cat
Firewall Alpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilities NetHogs dig host ip nmap
OpenVPN CentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Manager apk apt
Processes Management bg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searching grep whereis which
User Information groups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPN Alpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
2 comments… add one
  • Mike Sep 7, 2011 @ 7:22

    rsync -avr ? key “-a” already includes “-r” (from help:archive mode, equivalent to -rlptgoD)

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.