aboutsummaryrefslogtreecommitdiff
path: root/home/bin/backup
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2015-06-08 17:05:30 +0200
committerJakob Odersky <jodersky@gmail.com>2015-06-08 17:05:30 +0200
commit381eb6df61ce6d6e2c7bd926a5bd73f7b4c2333f (patch)
treeb1cf57dea578ac40c373cbdec969fce153a4d427 /home/bin/backup
downloaddotfiles-381eb6df61ce6d6e2c7bd926a5bd73f7b4c2333f.tar.gz
dotfiles-381eb6df61ce6d6e2c7bd926a5bd73f7b4c2333f.tar.bz2
dotfiles-381eb6df61ce6d6e2c7bd926a5bd73f7b4c2333f.zip
initial commit
Diffstat (limited to 'home/bin/backup')
-rwxr-xr-xhome/bin/backup58
1 files changed, 58 insertions, 0 deletions
diff --git a/home/bin/backup b/home/bin/backup
new file mode 100755
index 0000000..020e22e
--- /dev/null
+++ b/home/bin/backup
@@ -0,0 +1,58 @@
+#!/bin/bash
+set -e
+
+# source folder to back up, don't forget to add trailing slash
+: ${BACKUPSOURCE:="/home/jodersky/"}
+
+# backup root folder, i.e. the one that will contain all backups in separate sub-folders
+: ${BACKUPCAPSULE:="/media/jodersky/backup/backup/jakob/"}
+
+
+#destination folder to back up to
+destination="$BACKUPCAPSULE"/$(date +%Y-%m-%d_%H-%M-%S)
+
+#symbolic link to latest backup (if any)
+latest="$BACKUPCAPSULE/latest"
+
+# rsync options
+roptions=(
+ -a
+ -P
+ --copy-unsafe-links
+ --delete
+ --delete-excluded
+ --filter=": .rsyncignore"
+)
+
+# settings that are passed through arguments
+init=0; # initialise new backup
+dryrun=0; # perform a simulated run, don't backup any files
+
+# process arguments
+while [ $# -gt 0 ]
+do
+ if [ "$1" = "--init" ]; then
+ init=1
+ elif [ "$1" = "-n" ]; then
+ dryrun=1
+ else
+ echo "invalid argument: $1"
+ exit 1
+ fi
+ shift
+done
+
+if [ $init -eq 0 ]; then
+ roptions+=(--link-dest="$latest")
+fi
+if [ $dryrun -eq 1 ]; then
+ roptions+=(-n)
+ roptions+=(-vv)
+fi
+
+rsync "${roptions[@]}" "$BACKUPSOURCE" "$destination"
+
+if [ $dryrun -eq 0 ]; then
+ rm -f $latest
+ ln -s "$destination" "$latest"
+fi