This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
computing:rsyncrsnapshot [2018/05/18 07:54] – created oemb1905 | computing:rsyncrsnapshot [2023/04/10 21:29] (current) – oemb1905 | ||
---|---|---|---|
Line 1: | Line 1: | ||
------------------------------------------- | ------------------------------------------- | ||
- | #**rsync** | + | |
+ | * **Jonathan Haack** | ||
+ | * **Haack' | ||
+ | * **netcmnd@jonathanhaack.com** | ||
------------------------------------------- | ------------------------------------------- | ||
- | sudo rsync -avxHAX | + | Since I am backing up multiple remote hosts, I chose to create separate configs for each remote host instead of putting those destinations in the ''/ |
+ | |||
+ | #base config | ||
+ | config_version | ||
+ | snapshot_root | ||
+ | cmd_cp | ||
+ | cmd_rm | ||
+ | cmd_rsync | ||
+ | cmd_ssh | ||
+ | cmd_logger | ||
+ | verbose | ||
+ | loglevel | ||
+ | logfile | ||
+ | sync_first | ||
+ | use_lazy_deletes | ||
+ | retain | ||
+ | # | ||
+ | backup | ||
+ | backup | ||
+ | backup | ||
+ | backup | ||
+ | backup | ||
+ | |||
+ | Then, to run this, I use a simple script I created. Again, this script is just for running the localhost, so it can also be used for someone' | ||
+ | |||
+ | # | ||
+ | service="/ | ||
+ | logfile="/ | ||
+ | START1=" | ||
+ | touch $logfile | ||
+ | $service -V sync > $logfile | ||
+ | END1=" | ||
+ | DURATION1=$[ ${END1} - ${START1} ] | ||
+ | MINUTES=$[ ${DURATION1} / 60 ] | ||
+ | sed -i " | ||
+ | if | ||
+ | tail -n -5 $logfile | grep " | ||
+ | then | ||
+ | START1=" | ||
+ | echo " | ||
+ | $service -V alpha >> $logfile | ||
+ | END1=" | ||
+ | DURATION1=$[ ${END1} - ${START1} ] | ||
+ | MINUTES=$[ ${DURATION1} / 60 ] | ||
+ | sed -i " | ||
+ | mail -s " | ||
+ | rm $logfile | ||
+ | chown user:user -R / | ||
+ | chmod 770 -R / | ||
+ | else | ||
+ | echo " | ||
+ | mail -s " | ||
+ | rm $logfile | ||
+ | fi | ||
+ | |||
+ | Then, in ''/ | ||
+ | |||
+ | 0 0,14 * * * root /bin/bash / | ||
+ | |||
+ | Now that the localhost/ | ||
+ | |||
+ | #base config | ||
+ | config_version | ||
+ | snapshot_root | ||
+ | cmd_cp | ||
+ | cmd_rm | ||
+ | cmd_rsync | ||
+ | cmd_ssh | ||
+ | cmd_logger | ||
+ | verbose | ||
+ | loglevel | ||
+ | logfile | ||
+ | sync_first | ||
+ | use_lazy_deletes | ||
+ | retain | ||
+ | # | ||
+ | backup | ||
+ | backup | ||
+ | backup | ||
+ | backup | ||
+ | backup | ||
+ | |||
+ | 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, | ||
+ | |||
+ | # | ||
+ | service="/ | ||
+ | logfile="/ | ||
+ | host=" | ||
+ | START1=" | ||
+ | touch $logfile | ||
+ | $service -c / | ||
+ | END1=" | ||
+ | DURATION1=$[ ${END1} - ${START1} ] | ||
+ | MINUTES=$[ ${DURATION1} / 60 ] | ||
+ | sed -i " | ||
+ | if | ||
+ | tail -n -5 $logfile | grep " | ||
+ | then | ||
+ | START1=" | ||
+ | echo " | ||
+ | $service -c / | ||
+ | END1=" | ||
+ | DURATION1=$[ ${END1} - ${START1} ] | ||
+ | MINUTES=$[ ${DURATION1} / 60 ] | ||
+ | sed -i " | ||
+ | #echo " | ||
+ | mail -s " | ||
+ | rm $logfile | ||
+ | chown user:user -R / | ||
+ | chmod 770 -R / | ||
+ | else | ||
+ | echo " | ||
+ | mail -s " | ||
+ | rm $logfile | ||
+ | fi | ||
+ | |||
+ | Similarly, I need to set up a cronjob to execute this script in ''/ | ||
+ | |||
+ | 0 00,14 * * * root /bin/bash / | ||
+ | |||
+ | 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: | ||
+ | |||
+ | # | ||
+ | date=`date +" | ||
+ | log="/ | ||
+ | img=" | ||
+ | for i in $img; | ||
+ | do | ||
+ | touch $log | ||
+ | START0=" | ||
+ | rm -rf / | ||
+ | rm -rf / | ||
+ | rm -rf / | ||
+ | rm -rf / | ||
+ | rm -rf / | ||
+ | rm -rf / | ||
+ | rm -rf / | ||
+ | rm -rf / | ||
+ | rm -rf / | ||
+ | rm -rf / | ||
+ | END0=" | ||
+ | DURATION0=$[ ${END0} - ${START0} ] | ||
+ | MINUTES0=$[ ${DURATION0} / 60 ] | ||
+ | echo " | ||
+ | ${MINUTES0} minutes to complete." | ||
+ | mail -s " | ||
+ | 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 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. | ||
+ | |||
+ | sudo apt install rsnapshot | ||
+ | nano / | ||
+ | < | ||
+ | |||
+ | Uncomment the alpha, beta, gamma, and delta sections under //backup levels// section, enable the sync-first option, and specify the directories you want to backup (remember, '' | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <backup / | ||
+ | <backup /etc/ localhost> | ||
+ | |||
+ | Now, edit the default script inside ''/ | ||
+ | |||
+ | <0 */4 * * * root / | ||
+ | <30 3 * * * root / | ||
+ | <0 3 * * 1 root / | ||
+ | <30 2 1 * * root / | ||
+ | |||
+ | Personally, I use a simple script to ensure that the sync_first command completed before I run any of the '' | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | Of course, I have one of these for alpha, another for beta, and gamma, and so on until delta. | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | OK ... that's pretty much it for getting started with rsnapshot. | ||
+ | |||
+ | From remote server to target backup localhost, with alt port: | ||
+ | |||
+ | rsync -av --delete -e 'ssh -p 59333 -i / | ||
+ | |||
+ | From localhost to target remote backup server, with alt port: | ||
+ | |||
+ | rsync -av --delete -e 'ssh -p 59333 -i / | ||
+ | |||
+ | From remote server to target backup localhost, with standard port: | ||
+ | |||
+ | | ||
+ | |||
+ | From localhost to target remote backup server, with standard port: | ||
+ | |||
+ | sudo rsync -avi --delete / | ||
+ | |||
+ | Once you master these steps, checkout remote-upgrades, | ||
+ | |||
+ | This tutorial is a designated " | ||
+ | --- // |