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 23:07] – added syncthing dan
Line 1: Line 1:
 ====== Server & desktop backup solutions ====== ====== Server & desktop backup solutions ======
  
 +The first backups will take 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 10:
  
 <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 27:
 </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 49:
 DAEMONUSER="" DAEMONUSER=""
 DAEMONHOST="" DAEMONHOST=""
 +HOSTNAME=$(hostname)
 MINCHANGES=1 MINCHANGES=1
  
Line 68: Line 78:
 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 100:
 /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 - rsync and borg =====
  
-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" +</code> 
-EXCL="--exclude-from=/home/$real_user/backup-filter.rule" +<code> 
-DAEMONUSER="" +@daily /root/bsnapbackup.sh 
-DAEMONHOST="" +</code>
-MINCHANGES=1+
  
-# run this process with real low priority+  * ''@yearly'' 
 +  * ''@annually'' 
 +  * ''@monthly'' 
 +  * ''@weekly'' 
 +  * ''@daily'' 
 +  * ''@hourly'' 
 +  * ''@reboot''
  
-ionice -c 3 -p $$ 
-renice +12  -p $$ 
  
-# sync+===== Syncthing =====
  
-rsync $OPTS $EXCL $SRC $SNAP/latest >> $SNAP/rsync.log+Follow our [[en:server:services:syncthing|Syncthing]] tutorial for both devices (backup server and your data device).
  
-# 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 ) +==== Add device ====
-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+
  
 +Add the backup server to your client under ''Remote Devices''
  
-rsync -avAXHP --delete --password-file=/etc/rsyncd.password $SNAP rsync://$DAEMONUSER@$DAEMONHOST/archive/backup/server/$real_user 
-</code> 
  
 +==== Add folder ====
  
-== Exclude folder and files ==+  * Add a folder under ''Folder'' and select the folder you want to backup under ''General''.  
 +  * Select your backup server under ''Sharing''
 +  * Under ''File Versioning'' you could add ''Staggered File Versioning'' which gives you more certainty, but have a look at https://docs.syncthing.net/users/versioning.html and choose what suits you best. 
 +  * Also check ''Advanced'' and ''Folder type'' and again choose what suits you best. For example, Keepass can be used with ''Send & Receive'' if you want sync your database on both devices.
  
-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