aboutsummaryrefslogtreecommitdiff
path: root/scripts/backup.sh
blob: ebb7e2192a3871523b507b9b1d6659d369c37b92 (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"

OPT="-aPh"
EXCLUDE="--exclude-from=$exclude_file"
LATEST="/snapshots/$USER/latest"
LINK="--link-dest=$LATEST"
SRC="/home/$USER/"
SNAP="/snapshots/$USER/"
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