added cront-rsync file
parent
a3ea515551
commit
835e994ab3
|
@ -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
|
||||
|
|
|
@ -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.
|
Loading…
Reference in New Issue