-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.sh
executable file
·47 lines (39 loc) · 961 Bytes
/
backup.sh
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
39
40
41
42
43
44
45
46
47
#!/bin/bash
backup_path="${backup_path:=$1}"
: "${backup_path:?Missing backup_path, provide as argument (relative to home dir)}"
d=$(dirname "$0")
files_from=$(greadlink -f "$d")/restore.bom
shift
function doIt() {
echo "Backing up $HOME to ${backup_path} as a gzipped tar ball...";
echo "";
# Run in home folder
CURR_DIR=$(pwd)
cd || exit;
rsync \
--rsync-path="sudo rsync" \
--perms \
--recursive \
--compress \
--numeric-ids \
--links \
--hard-links \
--files-from="$files_from" \
-avh . ~/.tmp-backup-dir;
cd ~/.tmp-backup-dir && tar -czf ../.tmp-backup-dir.tgz . && cd -;
cd $CURR_DIR;
mv ~/.tmp-backup-dir.tgz $backup_path;
echo "Backed up successfully";
rm -rf ~/.tmp-backup-dir;
}
if [ "$1" == "--force" ] || [ "$1" == "-f" ]; then
doIt;
else
read -rp "Do you want to backup $(pwd) to ${backup_path}? (y/n) " -n 1;
echo "";
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
doIt;
fi;
fi;
unset doIt;
cd -;