-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbackup.sh
executable file
·69 lines (60 loc) · 1.69 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/sh
#
# creates user and system backup.
# pass option -f to create a full system backup instead of a compact one.
#
basedir=$(dirname "$0")
# exclude files and directories listed in these files,
# user-specific excludes:
excl_home="$basedir/backup_excludes_home.txt"
# system-specific excludes:
excl_sys="$basedir/backup_excludes_sys.txt"
# check for exclude files
if ! [ -f "$excl_home" ]; then
echo "exclude file \"$excl_home\" is missing!"
exit 1
fi
if ! [ -f "$excl_sys" ]; then
echo "exclude file \"$excl_sys\" is missing!"
exit 1
fi
# check for root
if ! [ $(id -u) = 0 ]; then
echo "warning: you should be root to run this script."
echo
sleep 5
fi
# check options
if [ "$1" = "-f" ]; then
full_backup="1"
fi
# tar options and extension
# -c create
# -p preserve permissions
# -j bzip2 compression
# -J xz compression
# -z gzip compression
# -v verbose output
# -f filename
tar_opts="cpJvf"
tar_ext="tar.xz"
# enable parallel compression for xz
export XZ_DEFAULTS="-T 0"
# create backup
date="$(date +%Y-%m-%d)"
file_base="backup-$(hostname)-$date"
file_home="${file_base}-home.$tar_ext"
echo "creating user backup $file_home"
time tar $tar_opts "$file_home" --exclude-from="$excl_home" /home/ /root/ 2>"${file_base}-home.log"
echo
if ! [ $full_backup ]; then
file_sys="${file_base}-sys.$tar_ext"
echo "creating system backup $file_sys"
time tar $tar_opts "$file_sys" --exclude-from="$excl_sys" /etc/ /var/spool/ /var/www/ 2>"${file_base}-sys.log"
else
file_sys="${file_base}-sys-full.$tar_ext"
echo "creating full system backup $file_sys"
time tar $tar_opts "$file_sys" --exclude-from="$excl_sys" / 2>"${file_base}-sys.log"
fi
echo
echo "done."