Shell script to mirror backups to another server in pull mode using rsync

in Categories Automation & Management, Backup last updated April 28, 2017

A shell script mirror remote server named and /backups directory to another server. The script use rsync command and also make sure a special directory mounted in local server. You must setup ssh keys (see “How To Set Up SSH Keys” for more info).

# Purpose: Mirror remote server backup using rsync command
# Author: Vivek Gite {}
# License: GPL ver 2.x+
# Note: Tested on Debian/Ubuntu and CentOS only.
# ------------------------------------------------------------
## change me ##
# Make sure offsite backup directory mounted
mount | grep -q ${_mnt}
if [ $? -eq 0 ]
  # Make dir if not found
  [ ! -d "$_dest" ] && mkdir -p "${_dest}"
  # alright mirror it. make sure you setup ssh-keys
  rsync --bwlimit 10000 --delete  -P -az -H --numeric-ids ${_user}@{_host}:${_dir} ${_dest}
  echo "$0: Error '${_dest}' not mounted." 
  exit 999

Share this on:

2 comment

  1. Hello
    Thanks for this script, I’ll need it soon :)
    I suggest using ‘mountpoint -q’ to check if the destination directory is mounted, it’s its goal :)

Leave a Comment