Computer at work
Manual local Backups
/home/xavi/scripts/backup_manual_pentinella.sh
#!/bin/bash ####################################### ### PARAMETERS TO CUSTOMIZE THE SCRIPT ####################################### ### Generic Label for the server ### MLABEL="xavi_pentinella" ### MySQL Server Login Info ### MUSER="mysqluser" MPASS="mysqlpass" MHOST="localhost" ### FTP SERVER Login info ### FTPU="ftpuser" FTPP="ftppass" FTPS="ftpserver" FTPF="./backups/pentinella" NOWD=$(date +"%Y-%m-%d") NOWT=$(date +"%H_%M_%S") ## Some paths defined MYSQL="$(which mysql)" MYSQLDUMP="$(which mysqldump)" BAKPATH="/home/xavi/backups_locals" # TODO: make the folliwng paths relative to this one BAK="backup_local_pentinella" TIKIFILESABSPATH="/var/www/tiki_files" # Relative paths to backup folders RBAK1="mysql" RBAK2="tikifiles" RBAK3="serverfiles" RBAK4="homexavifiles" EMAILF="ueb@vhir.org" EMAILT="xavier.depedro@vhir.org" SMTP="servirmta1.ir.vhebron.net" #### End of parameters ####################################### # Base path for backup folders BBAK=$BAKPATH/$BAK/$NOWD # Absolute paths to backup folders (base path + relative path) ABAK1=$BBAK/$RBAK1 ABAK2=$BBAK/$RBAK2 ABAK3=$BBAK/$RBAK3 ABAK4=$BBAK/$RBAK4 # Other variables used GZIP="$(which gzip)" # Relative paths for each log file RLOGF=log-$MLABEL-SUM.$NOWD.txt RLOGF1=log-$MLABEL-$RBAK1.$NOWD.txt RLOGF2=log-$MLABEL-$RBAK2.$NOWD.txt RLOGF3=log-$MLABEL-$RBAK3.$NOWD.txt RLOGF4=log-$MLABEL-$RBAK4.$NOWD.txt # Base log path (set by default to the same base path for backups) BLOGF=$BBAK # Absolute path for log files ALOGF=$BLOGF/$RLOGF ALOGF1=$BLOGF/$RLOGF1 ALOGF2=$BLOGF/$RLOGF2 ALOGF3=$BLOGF/$RLOGF3 ALOGF4=$BLOGF/$RLOGF4 ### These next parts (1) & (2) are related to the removal of previous files in these folders if they exist, and create dirs as needed for new set of periodic backups ### ## (1) To remove all previous backups locally at the server and at the same base backup folder, uncomment the following line #[ ! -d $BAKPATH/$BAK ] && mkdir -p $BAKPATH/$BAK || /bin/rm -f $BAKPATH/$BAK/* ## (2) To avoid removing previous backups from teh same day locally, keep the last part commeted out (with ## just in front of "|| /bin/rm -f ..." ) [ ! -d $ABAK1 ] && mkdir -p $ABAK1 # || /bin/rm -f $ABAK1/* [ ! -d $ABAK2 ] && mkdir -p $ABAK2 # || /bin/rm -f $ABAK2/* [ ! -d $ABAK3 ] && mkdir -p $ABAK3 # || /bin/rm -f $ABAK3/* [ ! -d $ABAK4 ] && mkdir -p $ABAK4 # || /bin/rm -f $ABAK4/* ### [ ! -d "$BAK" ] && mkdir -p "$BAK" ### DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')" for db in $DBS do FILE=$ABAK1/$db.$NOWD-$NOWT.gz $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE done ### Backup tikifiles ### #tar -czvf $ABAK2/00-$RBAK2-$MLABEL.$NOWD-$NOWT.tgz $TIKIFILESABSPATH/* > $ALOGF2 ### Backup serverfiles ### tar -czhvf $ABAK3/00-$RBAK3-$MLABEL.$NOWD-$NOWT.tgz /etc/* /root/.luckyBackup/* /root/.local/* /root/.ssh/* /root/.config/* > $ALOGF3 ### Backup home user files ### tar -czhvf $ABAK4/00-$RBAK4-$MLABEL.$NOWD-$NOWT.tgz /home/xavi/scripts/* /home/xavi/.local/* /home/xavi/.config/* /home/xavi/.Skype/* /home/xavi/.luckyBackup/* /home/xavi/.ssh/* /home/xavi/.purple/* > $ALOGF4 ### Send files over ftp ### #lftp -u $FTPU,$FTPP -e "mkdir $FTPF/$NOWD;cd $FTPF/$NOWD; mput $ABAK1/*.gz; mput $ABAK2/*.tgz; mput $ABAK3/*.tgz; quit" $FTPS > $ALOGF cd $ABAK1;ls -lh * > $ALOGF1 # Add a short summary with partial dir sizes and append all partial log files into one ($LOGF) cd $BBAK;du -h $RBAK1 $RBAK2 $RBAK3 $RBAK4 > $ALOGF;echo "" >> $ALOGF;echo "--- $RBAK2 uncompressed: ---------------" >> $ALOGF;du $TIKIFILESABSPATH -h --max-depth=2 >> $ALOGF ### Compress and Send log files ### tar -czvf $ALOGF1.tgz -C $BLOGF $RLOGF1 #tar -czvf $ALOGF2.tgz -C $BLOGF $RLOGF2 tar -czvf $ALOGF3.tgz -C $BLOGF $RLOGF3 tar -czvf $ALOGF4.tgz -C $BLOGF $RLOGF4 #lftp -u $FTPU,$FTPP -e "cd $FTPF/$NOWD; put $ALOGF1.tgz; put $ALOGF2.tgz; put $ALOGF3.tgz; put $ALOGF4.tgz; quit" $FTPS ### Send report through email ### sendemail -f $EMAILF -t $EMAILT -u '[Pentinella Manual Local Backup Report]' -m 'Short report attached' -a $ALOGF -a $ALOGF1 -s $SMTP -o tls=no
x
1
#!/bin/bash
2
#######################################
3
### PARAMETERS TO CUSTOMIZE THE SCRIPT
4
#######################################
5
### Generic Label for the server ###
6
MLABEL="xavi_pentinella"
7
### MySQL Server Login Info ###
8
MUSER="mysqluser"
9
MPASS="mysqlpass"
10
MHOST="localhost"
11
### FTP SERVER Login info ###
12
FTPU="ftpuser"
13
FTPP="ftppass"
14
FTPS="ftpserver"
15
FTPF="./backups/pentinella"
16
NOWD=$(date +"%Y-%m-%d")
17
NOWT=$(date +"%H_%M_%S")
18
## Some paths defined
19
MYSQL="$(which mysql)"
20
MYSQLDUMP="$(which mysqldump)"
21
BAKPATH="/home/xavi/backups_locals" # TODO: make the folliwng paths relative to this one
22
BAK="backup_local_pentinella"
23
TIKIFILESABSPATH="/var/www/tiki_files"
24
# Relative paths to backup folders
25
RBAK1="mysql"
26
RBAK2="tikifiles"
27
RBAK3="serverfiles"
28
RBAK4="homexavifiles"
29
EMAILF="ueb@vhir.org"
30
EMAILT="xavier.depedro@vhir.org"
31
SMTP="servirmta1.ir.vhebron.net"
32
33
#### End of parameters
34
#######################################
35
36
37
# Base path for backup folders
38
BBAK=$BAKPATH/$BAK/$NOWD
39
# Absolute paths to backup folders (base path + relative path)
40
ABAK1=$BBAK/$RBAK1
41
ABAK2=$BBAK/$RBAK2
42
ABAK3=$BBAK/$RBAK3
43
ABAK4=$BBAK/$RBAK4
44
# Other variables used
45
GZIP="$(which gzip)"
46
# Relative paths for each log file
47
RLOGF=log-$MLABEL-SUM.$NOWD.txt
48
RLOGF1=log-$MLABEL-$RBAK1.$NOWD.txt
49
RLOGF2=log-$MLABEL-$RBAK2.$NOWD.txt
50
RLOGF3=log-$MLABEL-$RBAK3.$NOWD.txt
51
RLOGF4=log-$MLABEL-$RBAK4.$NOWD.txt
52
# Base log path (set by default to the same base path for backups)
53
BLOGF=$BBAK
54
# Absolute path for log files
55
ALOGF=$BLOGF/$RLOGF
56
ALOGF1=$BLOGF/$RLOGF1
57
ALOGF2=$BLOGF/$RLOGF2
58
ALOGF3=$BLOGF/$RLOGF3
59
ALOGF4=$BLOGF/$RLOGF4
60
61
62
### These next parts (1) & (2) are related to the removal of previous files in these folders if they exist, and create dirs as needed for new set of periodic backups ###
63
64
## (1) To remove all previous backups locally at the server and at the same base backup folder, uncomment the following line
65
#[ ! -d $BAKPATH/$BAK ] && mkdir -p $BAKPATH/$BAK || /bin/rm -f $BAKPATH/$BAK/*
66
67
## (2) To avoid removing previous backups from teh same day locally, keep the last part commeted out (with ## just in front of "|| /bin/rm -f ..." )
68
[ ! -d $ABAK1 ] && mkdir -p $ABAK1 # || /bin/rm -f $ABAK1/*
69
[ ! -d $ABAK2 ] && mkdir -p $ABAK2 # || /bin/rm -f $ABAK2/*
70
[ ! -d $ABAK3 ] && mkdir -p $ABAK3 # || /bin/rm -f $ABAK3/*
71
[ ! -d $ABAK4 ] && mkdir -p $ABAK4 # || /bin/rm -f $ABAK4/*
72
### [ ! -d "$BAK" ] && mkdir -p "$BAK" ###
73
74
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
75
for db in $DBS
76
do
77
FILE=$ABAK1/$db.$NOWD-$NOWT.gz
78
$MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
79
done
80
81
### Backup tikifiles ###
82
#tar -czvf $ABAK2/00-$RBAK2-$MLABEL.$NOWD-$NOWT.tgz $TIKIFILESABSPATH/* > $ALOGF2
83
84
### Backup serverfiles ###
85
tar -czhvf $ABAK3/00-$RBAK3-$MLABEL.$NOWD-$NOWT.tgz /etc/* /root/.luckyBackup/* /root/.local/* /root/.ssh/* /root/.config/* > $ALOGF3
86
87
### Backup home user files ###
88
tar -czhvf $ABAK4/00-$RBAK4-$MLABEL.$NOWD-$NOWT.tgz /home/xavi/scripts/* /home/xavi/.local/* /home/xavi/.config/* /home/xavi/.Skype/* /home/xavi/.luckyBackup/* /home/xavi/.ssh/* /home/xavi/.purple/* > $ALOGF4
89
90
### Send files over ftp ###
91
#lftp -u $FTPU,$FTPP -e "mkdir $FTPF/$NOWD;cd $FTPF/$NOWD; mput $ABAK1/*.gz; mput $ABAK2/*.tgz; mput $ABAK3/*.tgz; quit" $FTPS > $ALOGF
92
cd $ABAK1;ls -lh * > $ALOGF1
93
# Add a short summary with partial dir sizes and append all partial log files into one ($LOGF)
94
cd $BBAK;du -h $RBAK1 $RBAK2 $RBAK3 $RBAK4 > $ALOGF;echo "" >> $ALOGF;echo "--- $RBAK2 uncompressed: ---------------" >> $ALOGF;du $TIKIFILESABSPATH -h --max-depth=2 >> $ALOGF
95
96
### Compress and Send log files ###
97
tar -czvf $ALOGF1.tgz -C $BLOGF $RLOGF1
98
#tar -czvf $ALOGF2.tgz -C $BLOGF $RLOGF2
99
tar -czvf $ALOGF3.tgz -C $BLOGF $RLOGF3
100
tar -czvf $ALOGF4.tgz -C $BLOGF $RLOGF4
101
#lftp -u $FTPU,$FTPP -e "cd $FTPF/$NOWD; put $ALOGF1.tgz; put $ALOGF2.tgz; put $ALOGF3.tgz; put $ALOGF4.tgz; quit" $FTPS
102
103
### Send report through email ###
104
sendemail -f $EMAILF -t $EMAILT -u '[Pentinella Manual Local Backup Report]' -m 'Short report attached' -a $ALOGF -a $ALOGF1 -s $SMTP -o tls=no
Crontab
Crontab for root as of Dec 29th, 2015
#Back In Time system entry, this will be edited by the gui: 0 14 * * 1 /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /usr/bin/backintime --backup-job >/dev/null 2>&1 #Back In Time system entry, this will be edited by the gui: 0 14 * * * /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /usr/bin/backintime --profile-id 2 --backup-job >/dev/null 2>&1 30 13 * * Wed sh '/home/xavi/scripts/backup_manual_pentinella.sh' #10 12 * * * cd /var/www/html/12.x/;php console.php index:rebuild > /dev/null 2>&1 # Sending "Daily reports" of watch-emails #* * * * * cd /var/www/html/12.x/;php console.php daily-report:send > /dev/null 2>&1
xxxxxxxxxx
11
1
#Back In Time system entry, this will be edited by the gui:
2
0 14 * * 1 /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /usr/bin/backintime --backup-job >/dev/null 2>&1
3
#Back In Time system entry, this will be edited by the gui:
4
0 14 * * * /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /usr/bin/backintime --profile-id 2 --backup-job >/dev/null 2>&1
5
6
30 13 * * Wed sh '/home/xavi/scripts/backup_manual_pentinella.sh'
7
8
#10 12 * * * cd /var/www/html/12.x/;php console.php index:rebuild > /dev/null 2>&1
9
10
# Sending "Daily reports" of watch-emails
11
#* * * * * cd /var/www/html/12.x/;php console.php daily-report:send > /dev/null 2>&1
Alias names for this page: Pentinella