RSync

    Source

    rsync -avz --log-file="/tmp/log.txt" -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o Port=24 -i /root/.ssh/private.key" --progress root@domain.tld:/home/ :/etc /c/${b}/
    
    rsync -avz -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o Port=24 -i /root/.ssh/private.key" --progress root@domain.tld:/home/ /c/${b}/
    

    Notes:

    • First we give source, and after destination.
    • in expression :/etc the : mean source((and also remote like we give root@)).
    • avoid to copy local rights --no-perms --no-owner --no-group
    • For VM i.e. raw files like images, use --sparse --inplace source
    • For large file, it can be useful to add --inplace --append --partial, thus it avoids to create a copy of the destination files and keeps the already uploaded part in case the connection shutdown.

    Backup script

    #!/bin/sh
    
    SSH_OPTIONS="-o Ciphers=aes256-ctr \
    -o HostKeyAlgorithms=ssh-rsa \
    -o MACs=hmac-sha2-512-etm@openssh.com,hmac-sha2-512 \
    -o KexAlgorithms=diffie-hellman-group-exchange-sha256 \
    -o Port=24"
    
    function backup() {
      local b="$1"
    
      echo "Backup $b"
    
      if [ -f "/tmp/backup_$b.log" ]
      then
        rm /tmp/backup_$b.log
      fi
    
      if [ -f "/tmp/backup_mail_$b.log" ]
      then
        rm /tmp/backup_mail_$b.log
      fi
    
      if [ ! -d "/c/${b}" ]
      then
        mkdir "/c/${b}"
      fi
    
    	if [ "$b" == "gitlab.society-lbl.com" ]
      then
        rsync ${options} -avz --log-file="/tmp/backup_${b}.log" -e "ssh ${SSH_OPTIONS} -i /root/.ssh/${b}.key" --progress root@${b}:/var/opt/gitlab :/var/backups :/etc :/root /home/sync/${b}/
      elif [ "$b" == "firefly.society-lbl.com" ]
      then
        rsync ${options} -avz --log-file="/tmp/backup_${b}.log" -e "ssh ${SSH_OPTIONS} -i /root/.ssh/${b}.key" --progress \
        root@${b}:/var/lib/docker/volumes \
        :/etc :/root \
        /home/sync/${b}/
      elif [ "$b" == "owncloud.society-lbl.com" ]
      then
        rsync ${options} -avz --log-file="/tmp/backup_${b}.log" -e "ssh ${SSH_OPTIONS} -i /root/.ssh/${b}.key" --progress root@${b}:/var/lib/docker/volumes/root_backup/_data :/var/lib/docker/volumes/root_files/_data/ :/etc :/root /home/sync/${b}/
      elif [ "$b" == "nextcloud.society-lbl.com" ]
      then
        rsync ${options} -avz --log-file="/tmp/backup_${b}.log" -e "ssh ${SSH_OPTIONS} -i /root/.ssh/${b}.key" --progress root@${b}:/var/lib/docker/volumes/root_nextcloud/_data/data :/var/lib/docker/volumes/root_db/_data :/etc :/root /home/sync/${b}/
      else
        rsync -avz --log-file="/tmp/backup_${b}.log" -e "ssh ${SSH_OPTIONS} -i /root/.ssh/${b}.key" --progress root@${b}:/home/ :/etc /c/${b}/
      fi
    
      if [ "$?" == "0" ]
      then
        title="success"
      else
        title="failed"
      fi
    
      echo "Subject: [nas-lbl] rsync ${title} ${b}">/tmp/backup_mail_${b}.log
      echo "">>/tmp/backup_mail_${b}.log
      cat "/tmp/backup_${b}.log">>/tmp/backup_mail_${b}.log
    
      #mail -s "[nas-lbl] rsync ${title} ${b}" laubosslink@society-lbl.com < "/tmp/${b}.log"
      sendmail "laubosslink@society-lbl.com" < "/tmp/backup_mail_${b}.log"
    }
    
    backup "singular.society-lbl.com"
    backup "plural.society-lbl.com"
    backup "gitlab.society-lbl.com"
    
    exit 0
    

    Note: If you need use rsync_backup for multiple backup on nas((maybe just for rnd2000)) with limited memory, use in ''/etc/crontab'' and not in ''/etc/cron.d'' to separate task from some hours.