-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbackup-subdirs.sh
More file actions
executable file
·80 lines (65 loc) · 1.74 KB
/
backup-subdirs.sh
File metadata and controls
executable file
·80 lines (65 loc) · 1.74 KB
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
#!/bin/bash
#
# Backup all directories within webroot
# use empty file ".DONT_BACKUP" to exclude any directory
#
#
#
# howto cron
# 15 0 * * * $HOME/scripts/file_backup.sh > logfile.log
#
# TODO
# hacer ionice
# days to retain backup. Used by recycler script
DEFRETAIN=14
LOGFILE=/home/webb_e/site_backups/WebrootBackup.log
#
#
BU_FILE_COUNT=0
#
# and name of backup source subfolder under the users home
WEBDIR=/var/www/vhosts/
#
# and name of dest folder for tar files
DESDIR=~/site_backups
IONICE="ionice -c3"
#alright, thats it for config, the rest is script
#########################################
cd ${WEBDIR}
TODAY=`date`
BU_FILE_COUNT=0
suffix=$(date +%m-%d-%Y)
printf "\n\n********************************************\n\tSite Backup r Log for:\n\t" | tee -a $LOGFILE
echo $TODAY | tee -a $LOGFILE
printf "********************************************\n" $TODAY | tee -a $LOGFILE
echo "see ${LOGFILE} for details"
#for DIR in $(ls | grep ^[a-z.]*$)
for DIR in $(ls | grep ^[a-z.]*$)
do
echo $DIR
#tar the current directory
if [ -f $DIR/.DONT_BACKUP ]
then
printf "\tSKIPPING $DIR as it contains ignore file\n" | tee -a $LOGFILE
else
cpath=${HOME}/${DESDIR}/${DIR}
#
#check if we need to make path
#
if [ -d $cpath ]
then
# direcotry exists, we're good to continue
filler="umin"
else
echo Creating $cpath
mkdir -p $cpath
echo $DEF_RETAIN > $cpath/.RETAIN_RULE
fi
#
${IONICE} tar -zcf ${HOME}/${DESDIR}/${DIR}/${DIR}_$suffix.tar.gz ./$DIR
BU_FILE_COUNT=$(( $BU_FILE_COUNT + 1 ))
fi
done
printf "\n\n********************************************\n" | tee -a $LOGFILE
echo $BU_FILE_COUNT sites were backed up
printf "********************************************\n" $TODAY | tee -a $LOGFILE