User Tools

Site Tools


computing:rsyncrsnapshot

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
computing:rsyncrsnapshot [2023/04/10 21:12] oemb1905computing:rsyncrsnapshot [2023/04/10 21:29] (current) oemb1905
Line 54: Line 54:
           mail -s "[$(hostname -f)]-rsnap-success-$(date)" alerts@alerts.com < $logfile           mail -s "[$(hostname -f)]-rsnap-success-$(date)" alerts@alerts.com < $logfile
           rm $logfile           rm $logfile
-          chown sexa:sexa -R /mnt/backups/rsnapback/localhost.domain/+          chown user:user -R /mnt/backups/rsnapback/localhost.domain/
           chmod 770 -R /mnt/backups/rsnapback/localhost.domain/           chmod 770 -R /mnt/backups/rsnapback/localhost.domain/
   else   else
Line 89: Line 89:
   backup                  root@domain.com:/root/                 root/   backup                  root@domain.com:/root/                 root/
  
-Now that the config is setup, you use a script very similar to the localhost script above, but note the syntax changes for sync and alpha that will specify to rsnapshot to use this particular configuration file:+Now that the config is setup, you use a script very similar to the localhost script above, but note the syntax changes for sync and alpha that will specify to rsnapshot to use this particular configuration file. Additionally, just like the localhost, I specified for rsnapshot to retain a snapshot called alpha for 90 days, which suits my use case. Here's the script for the remote hosts:
  
 +  #!/bin/bash
 +  service="/usr/bin/rsnapshot"
 +  logfile="/home/sexa/logs/domain.com.log"
 +  host="domain.com"
 +          START1="$(date +%s)"
 +          touch $logfile
 +          $service -c /etc/rsnapshot/rsnapshot-$host.conf -V sync > $logfile
 +          END1="$(date +%s)"
 +          DURATION1=$[ ${END1} - ${START1} ]
 +          MINUTES=$[ ${DURATION1} / 60 ]
 +          sed -i "1s/^/Jonathan, at $(date), the rsnapshot sync took exactly ${DURATION1} seconds which is approximately ${MINUTES} minutes to complete.\n/" $logfile
 +  if
 +          tail -n -5 $logfile | grep "completed"
 +  then
 +          START1="$(date +%s)"
 +          echo "Jonathan, at $(date), $(hostname -f) ran a sync that completed so I am now running alpha."
 +          $service -c /etc/rsnapshot/rsnapshot-$host.conf -V alpha >> $logfile
 +          END1="$(date +%s)"
 +          DURATION1=$[ ${END1} - ${START1} ]
 +          MINUTES=$[ ${DURATION1} / 60 ]
 +          sed -i "1s/^/Jonathan, at $(date), the rsnapshot alpha took exactly ${DURATION1} seconds which is approximately ${MINUTES} minutes to complete.\n/" $logfile
 +          #echo "Jonathan, at $(date), the rsnapshot alpha took exactly ${DURATION1} seconds which is approximately ${MINUTES} minutes to complete." | tee -a $logfile
 +          mail -s "[${host}]-rsnap-success-$(date)" alerts@alerts.com < $logfile
 +          rm $logfile
 +          chown user:user -R /mnt/backups/rsnapback/$host/
 +          chmod 770 -R /mnt/backups/rsnapback/$host/
 +  else
 +          echo "Jonathan, at $(date), $(hostname -f) ran a sync that failed and I am now notifying you."
 +          mail -s "[${host}]-rsnap-failure-$(date)" alerts@alerts.com < $logfile
 +          rm $logfile
 +  fi
 +
 +Similarly, I need to set up a cronjob to execute this script in ''/etc/cron.d/rsnapshot'' for which I once again chose twice a day:
 +
 +  0 00,14 * * * root /bin/bash /usr/local/bin/rsnap-alpha-comain.com.sh > /dev/null 2>&1
 +
 +You would think the retain 90 would delete the old ones, but it does not seem to work for whatever reason, and so I setup a small script to delete anything past 90 which runs daily at 8am, well after the last snapshot completed. It's also a loop which will make sure to prune all the snapshots between 90-100. If the script fails, it's possible that some snapshots could run past 90, hence including a ten day buffer. Here's the backup scrip, and trigger warning, it's a kludge:
 +
 +  #!/bin/bash
 +  date=`date +"%Y%m%d-%H:%M:%S"`
 +  log="/home/logs/rsnap-delete.log"
 +  img="domain.com domain.org domain.net"
 +  for i in $img;
 +  do
 +  touch $log
 +  START0="$(date +%s)"
 +  rm -rf /mnt/backups/rsnapback/$i/alpha.90
 +  rm -rf /mnt/backups/rsnapback/$i/alpha.91
 +  rm -rf /mnt/backups/rsnapback/$i/alpha.92
 +  rm -rf /mnt/backups/rsnapback/$i/alpha.93
 +  rm -rf /mnt/backups/rsnapback/$i/alpha.94
 +  rm -rf /mnt/backups/rsnapback/$i/alpha.95
 +  rm -rf /mnt/backups/rsnapback/$i/alpha.96
 +  rm -rf /mnt/backups/rsnapback/$i/alpha.97
 +  rm -rf /mnt/backups/rsnapback/$i/alpha.98
 +  rm -rf /mnt/backups/rsnapback/$i/alpha.99
 +  END0="$(date +%s)"
 +  DURATION0=$[ ${END0} - ${START0} ]
 +  MINUTES0=$[ ${DURATION0} / 60 ]
 +  echo "Jonathan, at $(date), the rsnapshot purge took exactly ${DURATION0} seconds which is approximately 
 +  ${MINUTES0} minutes to complete." | tee -a $log
 +  mail -s "[rsnap-delete-$i]-$(hostname -f)-$(date)" alerts@alerts.com < $log
 +  rm $log
 +  done
  
 +So far, everything is working great. In the future, I would like to debug why rsnapshot retains more than the 90 specified in alpha and/or polish up the delete script some more. I would also like to improve the rsnap-alpha script to check for a process id rather than checking the sync log for the conditional upon which it executes the script. I already have a colleague who has a good template for doing that and it's in progress. In the mean time, however, I've already used this for 120 days or so and had to use it to restore some versions I accidentally deleted. Very pleased for now. 
  
  
 +----
  
 +I've decided to keep this older information below, as it includes a more standard setup for single host, including alpha, beta, gamma, and delta versions. 
  
-[BEGIN OLDLet's start with rsnapshot.  Before you begin, you must already know how to add a hard drive to your system, a mount point, and an appropriate fstab entry.  This also assumes you have an MTA properly set-up in order to send email.  To create a basic configuration, do the following:+[Begin old tutorial] Before you begin, you must already know how to add a hard drive to your system, a mount point, and an appropriate fstab entry.  This also assumes you have an MTA properly set-up in order to send email.  To create a basic configuration, do the following:
  
   sudo apt install rsnapshot   sudo apt install rsnapshot
Line 149: Line 216:
 This tutorial is a designated "Invariant Section" of the "Technotronic" section of Haack's Wiki as described on the [[https://jonathanhaack.com/dokuwiki/doku.php?id=start|Start Page]]. This tutorial is a designated "Invariant Section" of the "Technotronic" section of Haack's Wiki as described on the [[https://jonathanhaack.com/dokuwiki/doku.php?id=start|Start Page]].
  
- --- //[[jonathan@haacksnetworking.com|oemb1905]] 2020/01/27 12:55// + --- //[[jonathan@haacksnetworking.org|oemb1905]] 2023/04/10 15:16//  
-  +
computing/rsyncrsnapshot.txt · Last modified: 2023/04/10 21:29 by oemb1905