added cront-rsync file

Lucas Frérot 2024-12-26 13:38:26 +01:00
parent a3ea515551
commit 835e994ab3
No known key found for this signature in database
GPG Key ID: 03B54A50E3FBA7E8
2 changed files with 38 additions and 1 deletions

@ -1,6 +1,6 @@
Having an external backup of your home directory is mandatory. Here are a few ways to back up your data, from simplest to most feature rich.
- Using cron + rsync (can be used to backup to a server)
- Using [cron + rsync](cron-rsync) (can be used to backup to a server)
- On Gnome: using DejaDup (duplicity)
- On KDE/Plasma: using KBackup or kup
- (advanced) using zfs or btrfs snapshots

37
cron-rsync.md Normal file

@ -0,0 +1,37 @@
# Backups with cron and rsync
Here is a sample script for incremental backups with rsync. It uses physical
links to avoid data duplication.
```bash
#!/usr/bin/env bash
set -euo pipefail
if [ $# -ne 2 ]; then
echo "usage: $0 source destination"
exit 1
fi
SRCDIR=$(realpath $1)
BACKUPDIR=$(realpath $2)
CURRENTDIR="$BACKUPDIR/current"
POSTFIX=$(date --iso-8601=seconds)
CURRENT_BCKP="$BACKUPDIR/$POSTFIX/"
# Backup nextcloud data
rsync -Aax --info=STATS1 --delete --link-dest="$CURRENTDIR" "$SRCDIR" "$CURRENT_BCKP"
# Create "current" symbolic link to latest backup
ln -fns $(basename "$CURRENT_BCKP") "$CURRENTDIR"
```
One can use cron to execute a daily backup to an external drive. To add a new
scheduled task, use `crontab -e` and something like:
```
0 12 * * * /path/to/backup.sh $HOME /mnt/drive/path/to/backupdir
```
This will run the backup task every day at noon.