Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision Next revisionBoth sides next revision | ||
en:backup:server [2022/02/25 21:13] – created dan | en:backup:server [2022/05/29 10:21] – [Script] 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 8: | Line 9: | ||
The snapshots are stored locally and remotely via rsync daemon. | The snapshots are stored locally and remotely via rsync daemon. | ||
- | <alert type=" | + | <alert type=" |
+ | |||
+ | ==== Dependencies ==== | ||
+ | |||
+ | The script needs '' | ||
+ | |||
+ | < | ||
+ | pacman -S inetutils | ||
+ | </ | ||
==== Credentials ==== | ==== Credentials ==== | ||
Line 17: | Line 27: | ||
</ | </ | ||
- | + | ==== Script | |
- | === Server | + | |
- | + | ||
- | + | ||
- | == Script | + | |
Add your details for '' | Add your details for '' | ||
+ | < | ||
+ | nano / | ||
+ | </ | ||
< | < | ||
#!/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=/ | |
- | rsync -avAXHP --delete --password-file=/ | + | </ |
+ | < | ||
+ | chmod +x /root/ | ||
</ | </ | ||
- | == Exclude folder and files == | + | === Exclude folder and files === |
- | This is an example | + | This is an example. Add anything you don't need to backup. And change home '' |
< | < | ||
- | backup-filter.rule | + | nano /root/backup-filter.rule |
</ | </ | ||
< | < | ||
Line 88: | Line 100: | ||
/mnt/* | /mnt/* | ||
/media/* | /media/* | ||
- | /home/* | + | /lost+found |
+ | # root user | ||
/ | / | ||
- | /lost+found | + | /root/ |
+ | # Home user | ||
+ | / | ||
</ | </ | ||
- | === Desktop (home) === | ||
+ | ===== borg ===== | ||
- | == Script == | + | Follow our [[en: |
- | Add your details for '' | + | The snapshots are stored remotely via ssh. |
+ | |||
+ | ==== Script ==== | ||
+ | |||
+ | Don't forget to create the borg repo first and add the credentials to the script. | ||
+ | < | ||
+ | borg init --encryption=keyfile-blake2 --make-parent-dirs ssh:// | ||
+ | </ | ||
< | < | ||
#!/bin/sh | #!/bin/sh | ||
- | ## Based on: | + | # Setting this, so the repo does not need to be given on the commandline: |
- | ## my own rsync-based snapshot-style backup procedure | + | export BORG_REPO=ssh:// |
- | ## (cc) marcio rps AT gmail.com | + | |
- | # config vars | + | # See the section " |
+ | export BORG_PASSPHRASE=' | ||
- | real_user=$SUDO_USER | + | # some helpers and error handling: |
+ | info() { printf "\n%s %s\n\n" | ||
+ | trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM | ||
- | SRC="/ | + | info "Starting |
- | SNAP="/ | + | |
- | OPTS=" | + | |
- | EXCL=" | + | |
- | DAEMONUSER="" | + | |
- | DAEMONHOST=" | + | |
- | MINCHANGES=1 | + | |
- | # run this process with real low priority | + | # Backup the most important directories into an archive named after |
+ | # the machine | ||
- | ionice | + | borg create |
- | renice +12 | + | |
+ | --filter AMEhsx | ||
+ | --list | ||
+ | --stats | ||
+ | --progress | ||
+ | --verbose | ||
+ | --show-version | ||
+ | --show-rc | ||
+ | --compression zstd, | ||
+ | --exclude-caches | ||
+ | --exclude '/ | ||
+ | --exclude '/ | ||
+ | \ | ||
+ | ::' | ||
+ | /etc \ | ||
+ | /home \ | ||
+ | /root \ | ||
+ | /var \ | ||
- | # sync | + | backup_exit=$? |
- | rsync $OPTS $EXCL $SRC $SNAP/ | + | info " |
- | # check if enough has changed | + | # Use the `prune` subcommand to maintain 7 daily, 4 weekly |
- | # make a hardlinked copy named as the date | + | # archives of THIS machine. The ' |
+ | # limit prune' | ||
+ | # other machines' | ||
- | COUNT=$( wc -l $SNAP/ | + | borg prune \ |
- | if [ $COUNT | + | |
- | | + | --prefix ' |
- | if [ ! -e $SNAP/ | + | --show-rc \ |
- | cp -al $SNAP/ | + | --keep-daily |
- | chmod u+w $SNAP/ | + | |
- | mv $SNAP/ | + | |
- | chmod u-w $SNAP/ | + | |
- | fi | + | |
- | fi | + | |
+ | prune_exit=$? | ||
- | rsync -avAXHP --delete --password-file=/ | + | # use highest exit code as global exit code |
- | </ | + | global_exit=$(( backup_exit > prune_exit ? backup_exit |
+ | if [ ${global_exit} -eq 0 ]; then | ||
+ | info " | ||
+ | elif [ ${global_exit} -eq 1 ]; then | ||
+ | info " | ||
+ | else | ||
+ | info " | ||
+ | fi | ||
- | == Exclude folder | + | exit ${global_exit} |
+ | </ | ||
+ | ===== Crontab - rsync and borg ===== | ||
- | This is an example. Add anything you don't need to backup. | + | Follow our [[en: |
< | < | ||
- | backup-filter.rule | + | @daily / |
</ | </ | ||
< | < | ||
- | backup/ | + | @daily |
- | .cache/ | + | |
</ | </ | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | |||
+ | ===== Syncthing ===== | ||
+ | |||
+ | Follow our [[en: | ||
+ | |||
+ | |||
+ | ==== Add device ==== | ||
+ | |||
+ | Add the backup server to your client under '' | ||
+ | |||
+ | |||
+ | ==== Add folder ==== | ||
+ | |||
+ | * Add a folder under '' | ||
+ | * Select your backup server under '' | ||
+ | * Under '' | ||
+ | * Also check '' | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ |