en:backup:server

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
en:backup:server [2022/02/25 21:29] – [rsync] added borg link in alert info danen:backup:server [2022/02/26 07:34] – [Server & desktop backup solutions] Added information about how long a backup will take. dan
Line 1: Line 1:
 ====== Server & desktop backup solutions ====== ====== Server & desktop backup solutions ======
  
 +The first backup of the two options takes a while. The following ones are much faster, but it depends on how much you change. Only the changes are saved.
 ===== rsync ===== ===== rsync =====
  
Line 9: Line 9:
  
 <alert type="danger" icon="fa fa-warning">This backup solution is only recommended for an internal network. Use an encrypted backup method with [[en:backup:server#borg|borg]] instead.</alert> <alert type="danger" icon="fa fa-warning">This backup solution is only recommended for an internal network. Use an encrypted backup method with [[en:backup:server#borg|borg]] instead.</alert>
 +
 +==== Dependencies ====
 +
 +The script needs ''inetutils'' for ''hostname'' command.
 +
 +<code>
 +pacman -S inetutils
 +</code>
 +
  
 ==== Credentials ==== ==== Credentials ====
Line 17: Line 26:
 </code> </code>
  
- +==== Script ====
-=== Server === +
- +
- +
-== Script ==+
  
 Add your details for ''DAEMONUSER=""'' and ''DAEMONHOST=""''. Add your details for ''DAEMONUSER=""'' and ''DAEMONHOST=""''.
  
 +<code>
 +nano /root/rsnapbackup.sh
 +</code>
 <code> <code>
 #!/bin/sh #!/bin/sh
Line 40: Line 48:
 DAEMONUSER="" DAEMONUSER=""
 DAEMONHOST="" DAEMONHOST=""
 +HOSTNAME=$(hostname)
 MINCHANGES=1 MINCHANGES=1
  
Line 68: Line 77:
 fi fi
  
- +rsync -avAXHP --delete --password-file=/etc/rsyncd.password $SNAP rsync://$DAEMONUSER@$DAEMONHOST/archive/backup/$HOSTNAME 
-rsync -avAXHP --delete --password-file=/etc/rsyncd.password $SNAP rsync://$DAEMONUSER@$DAEMONHOST/archive/backup/server/root+</code> 
 +<code> 
 +chmod +x /root/rsnapbackup.sh
 </code> </code>
  
  
-== Exclude folder and files ==+=== Exclude folder and files ===
  
-This is an example and widely used as a starting point for a server. Add anything you don't need to backup.+This is an example. Add anything you don't need to backup. And change home ''$USER''.
  
 <code> <code>
-backup-filter.rule+nano /root/backup-filter.rule
 </code> </code>
 <code> <code>
Line 88: Line 99:
 /mnt/* /mnt/*
 /media/* /media/*
-/home/* 
-/root/backup/* 
 /lost+found /lost+found
 +# root user
 +/root/backup/*
 +/root/.cache/*
 +# Home user
 +/home/$USER/.cache/*
 </code> </code>
  
-=== Desktop (home) === 
  
 +===== borg =====
  
-== Script ==+<alert type="info" icon="fa fa-wrench">Work in progress</alert>
  
-Add your details for ''DAEMONUSER=""'' and ''DAEMONHOST=""''.+Follow our [[en:server:services:borg|borg]] tutorial first.
  
-<code> +The snapshots are stored remotely via ssh. 
-#!/bin/sh+
  
-## Based on: 
-## my own rsync-based snapshot-style backup procedure 
-## (cc) marcio rps AT gmail.com 
  
-# config vars+===== Crontab =====
  
-real_user=$SUDO_USER+Follow our [[en:server:services:crontab|crontab]] tutorial first and add the following for your root user:
  
-SRC="/home/$real_user/" +<code
-SNAP="/home/$real_user/backup/" +@daily /root/rsnapbackup.sh
-OPTS="-rltgoiP --delay-updates --delete --chmod=a-w" +
-EXCL="--exclude-from=/home/$real_user/backup-filter.rule" +
-DAEMONUSER="" +
-DAEMONHOST="" +
-MINCHANGES=1 +
- +
-# run this process with real low priority +
- +
-ionice -c 3 -p $$ +
-renice +12  -p $$ +
- +
-# sync +
- +
-rsync $OPTS $EXCL $SRC $SNAP/latest >> $SNAP/rsync.log +
- +
-# check if enough has changed and if so +
-# make a hardlinked copy named as the date +
- +
-COUNT=$( wc -l $SNAP/rsync.log|cut -d" " -f1 ) +
-if [ $COUNT -gt $MINCHANGES ] ; then +
-        DATETAG=$(date +%Y-%m-%d-%H:%M) +
-        if [ ! -e $SNAP/$DATETAG ] ; then +
-                cp -al $SNAP/latest $SNAP/$DATETAG +
-                chmod u+w $SNAP/$DATETAG +
-                mv $SNAP/rsync.log $SNAP/$DATETAG +
-               chmod u-w $SNAP/$DATETAG +
-         fi +
-fi +
- +
- +
-rsync -avAXHP --delete --password-file=/etc/rsyncd.password $SNAP rsync://$DAEMONUSER@$DAEMONHOST/archive/backup/server/$real_user+
 </code> </code>
  
 +  * ''@yearly''
 +  * ''@annually''
 +  * ''@monthly''
 +  * ''@weekly''
 +  * ''@daily''
 +  * ''@hourly''
 +  * ''@reboot''
  
-== Exclude folder and files == 
- 
-This is an example. Add anything you don't need to backup. 
- 
-<code> 
-backup-filter.rule 
-</code> 
-<code> 
-backup/ 
-.cache/ 
-</code> 
  • en/backup/server.txt
  • Last modified: 2022/10/24 08:24
  • by 127.0.0.1