-
Notifications
You must be signed in to change notification settings - Fork 1
/
backup.gutenberg.sh
executable file
·47 lines (40 loc) · 1.1 KB
/
backup.gutenberg.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/zsh
DDIR=/backups
if [ ! -d $DDIR ]; then
echo "Destination directory does not exist. Please create it using admin permissions and make sure to protect it"
exit 2
fi
backall() {
BDIR=$1
PREFIX=$2
SKIPEXP=$3
for i in $BDIR/*; do
skip=$( echo $i | grep -E -c $SKIPEXP )
if [ "$skip" -gt 0 ]; then
echo "Skipping $i"
else
echo "Backing up $i to $PREFIX.${i:t}.tar.gz"
tar zcf $PREFIX.${i:t}.tar.gz $i
fi
done
}
backdir() {
BDIR=$1
PREFIX=$2
SKIPEXP=$3
for i in $BDIR; do
skip=$( echo $i | grep -E -c $SKIPEXP )
if [ "$skip" -gt 0 ]; then
echo "Skipping $i"
else
echo "Backing up $i to $PREFIX${i:t}.tar.gz"
tar zcf $PREFIX${i:t}.tar.gz $i
fi
done
}
data=$(date +"%Y-%m-%d-%H-%M")
mkdir $DDIR/$data
cd $DDIR/$data
backall "/home" "$DDIR/$data/home" "/(lost\+found|ariele|backups|home.old|archived)$"
backdir "/etc" "$DDIR/$data/" "/(lost\+found)$"
backdir "/var/www" "$DDIR/$data/var." "/(lost\+found|packages)$"