aboutsummaryrefslogtreecommitdiff
path: root/scripts/backup.sh
blob: ec595edb64a17a827ce2ed4b4b40a3a0b0b9c4e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env bash

# Delete old snapshots
find "/snapshots/$USER" -maxdepth 1 -mtime +120 -type d -execdir rm -rf {} +

exclude_file="$HOME/.backup-exclude-list.txt"

OPT="-aPh"
EXCLUDE="--exclude-from=$exclude_file"
LINK="--link-dest=/snapshots/$USER/latest"
SRC="/home/$USER/"
SNAP="/snapshots/$USER/"
LATEST="/snapshots/$USER/latest"
date=$(date "+%Y-%b-%d:_%T")

[ ! -d $SNAP ] && mkdir -p $SNAP


rsync $OPT $LINK $EXCLUDE $SRC ${SNAP}$date

rm -f $LATEST
ln -s ${SNAP}$date $LATEST