-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystembackup.sh
executable file
·106 lines (88 loc) · 2.98 KB
/
systembackup.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
#
# customized system backup script -
# creates a tar.gz archive of root and home filesystems
# filtering out unneeded directories and undesired content
#
# * home filesystem: iso files are ommitted
#
# ==========================================================
# variable definitions
# ==========================================================
hostname=$HOSTNAME
date=$(date +%Y.%m.%d_%H.%M)
bkup_dir=/mnt/backup/$HOSTNAME
bkup_filename=backup_$hostname\_$date
bkup_logfile=$bkup_dir/backups.log
# ----------------------------------------------------------
# change directory to the system root
# ----------------------------------------------------------
cd /
# ----------------------------------------------------------
# verify backup share is mounted, else mount it
# ----------------------------------------------------------
mountpoint -q /mnt/backup || \
mount.nfs storage.lab.acrocker.com:/srv/nfs/backup /mnt/backup
# ----------------------------------------------------------
# verify host-specific directory exists, else create it
# ----------------------------------------------------------
if [[ ! -d $bkup_dir ]]; then
mkdir $bkup_dir
fi
# ==========================================================
# ROOT
# ==========================================================
# make backup of root filesystem in backup share
# ----------------------------------------------------------
fsystem=root
tar -cvzf $bkup_dir/$bkup_filename\_$fsystem.tar.gz \
--one-file-system \
--exclude=/home \
--exclude=/proc \
--exclude=/tmp \
--exclude=/mnt \
--exclude=/dev \
--exclude=/sys \
--exclude=/run \
--exclude=/media \
--exclude=/var/log \
--exclude=/var/cache/pacman \
--exclude=/var/cache/apt \
--exclude=/var/cache/yum \
--exclude=/home/*/.gvfs \
--exclude=/home/*/.cache \
--exclude=/home/*/.local/share/Trash \
--exclude=/*.iso \
/
# ----------------------------------------------------------
# log backup completeion
# ----------------------------------------------------------
echo "backup complete -- host: $hostname\ -- type: $fsystem\ -- $date " >> $bkup_logfile
# ==========================================================
# HOME
# ==========================================================
# make backup of home filesystem in backup share
# ----------------------------------------------------------
fsystem=home
tar -cvzf $bkup_dir/$bkup_filename\_$fsystem.tar.gz \
--one-file-system \
--exclude=/proc \
--exclude=/tmp \
--exclude=/mnt \
--exclude=/dev \
--exclude=/sys \
--exclude=/run \
--exclude=/media \
--exclude=/var/log \
--exclude=/var/cache/pacman \
--exclude=/var/cache/apt \
--exclude=/var/cache/yum \
--exclude=/home/*/.gvfs \
--exclude=/home/*/.cache \
--exclude=/home/*/.local/share/Trash \
--exclude=/*.iso \
/home
# ----------------------------------------------------------
# log backup completeion
# ----------------------------------------------------------
echo "backup complete -- host: $hostname\ -- type: $fsystem\ -- $date " >> $bkup_logfile