forked from shawwn/scrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backupdir
executable file
·39 lines (32 loc) · 916 Bytes
/
backupdir
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# usage examples:
#
# backup the ~/bin folder minus large binary files:
# $ backupbin
#
# backup the entire ~/bin folder
# $ backupbin all
#
#=====================================================================
# main
#=====================================================================
BAK="$1"
DST="${2:-.}"
# DST="$(canonicalize_path "$(resolve_symlinks "$DST")")"
DST="$(realpath "$(realpath "$DST")")"
shift 1
shift 1
NAME="$(basename "$BAK")"
NAME="$NAME-`utcstamp`";
if [ ! -z "$LABEL" ]; then
NAME="$NAME-$LABEL"
fi
BAK_DIR="$(dirname "$BAK")"
BAK_SUBDIR="$(basename "$BAK")"
# use $@ to pass in e.g. --exclude=path/some_subfolder
[ ! -d "$DST" ] && mkdir -p "$DST"
cat <<.
\$(cd "$BAK_DIR" ; tar $@ -czvf "$DST/$NAME.tar.gz" "$BAK_SUBDIR/")
.
$(cd "$BAK_DIR" ; tar $@ -czvf "$DST/$NAME.tar.gz" "$BAK_SUBDIR/")
echo "$NAME.tar.gz saved to $(dirname "$DST/$NAME.tar.gz")"