Script for the amazon s3 backup by s3cmd
This is the script for the amazon s3 bucket backup in the s3 bucket with the name and date, to do flow this page and write the script below
#vim s3cmd.sh
1 #!/bin/bash
2
3
4
5 ##Notification email address
6
7 _EMAIL=xyz@xyz.com
8
9
10
11 ERRORLOG=/var/log/backuplogs/backup.err`date +%F`
12
13 ACTIVITYLOG=/var/log/backuplogs/activity.log`date +%F`
14
15
16
17 ##Directory which needs to be backed in s3 bucket
18
19 SOURCE=/root/Desktop/lotos3/
20
21
22
23 ##Name of the backup in bucket to be stored with date and time
24
25 DESTINATION=`date +%F`
26
27
28
29 ##Backup degree(this is for to maintain how many backup and delete the old)
30
31 DEGREE=7
32
33
34
35 #Clear the logs if the script is executed second time
36
37 :> ${ERRORLOG}
38
39 :> ${ACTIVITYLOG}
40
41
42
43 ##Uploading the daily backup to Amazon s3
44
45 /usr/bin/s3cmd -r put ${SOURCE} s3://MClouds-757cf3e2e4/${DESTINATION}/ 1>>${ACTIVITYLOG} 2>>${ERRORLOG}
46
47 ret2=$?
48
49
50
51 ##Sent email alert
52
53 msg="BACKUP NOTIFICATION ALERT FROM `hostname`"
54
55
56
57 if [ $ret2 -eq 0 ];then
58
59 msg1="Amazon s3 Backup Uploaded Successfully"
60
61 else
62
63 msg1="Amazon s3 Backup Failed!!\n Check ${ERRORLOG} for more details"
64
65 fi
66
67 echo -e "$msg1"|mail -s "$msg" ${_EMAIL}
68
69
70
71 #######################
72
73 ##Deleting backup's older than DEGREE days
74
75 ## Delete from both server and amazon
76
77 #######################
78
79 DELETENAME=$(date --date="${DEGREE} days ago" +%F)
80
81
82
83 /usr/bin/s3cmd -r --force del s3://MClouds-757cf3e2e4/${DELETENAME} 1>>${ACTIVITYLOG} 2>>${ERRORLOG}
84
85
Cronjobs:
Daily Backup with 7 days retention:It takes daily full backup
35 10 * * * /root/s3cmdbackup.sh
Monthly Backup: It takes a full backup every month 15th and 28th dates
40 2 15,28 * * /root/s3cmdbackup.sh
Yearly backup: It takes a full backup every year december 31st
20 23 31 12 * /root/s3cmdbackup.sh
This is the script for the amazon s3 bucket backup in the s3 bucket with the name and date, to do flow this page and write the script below
#vim s3cmd.sh
1 #!/bin/bash
2
3
4
5 ##Notification email address
6
7 _EMAIL=xyz@xyz.com
8
9
10
11 ERRORLOG=/var/log/backuplogs/backup.err`date +%F`
12
13 ACTIVITYLOG=/var/log/backuplogs/activity.log`date +%F`
14
15
16
17 ##Directory which needs to be backed in s3 bucket
18
19 SOURCE=/root/Desktop/lotos3/
20
21
22
23 ##Name of the backup in bucket to be stored with date and time
24
25 DESTINATION=`date +%F`
26
27
28
29 ##Backup degree(this is for to maintain how many backup and delete the old)
30
31 DEGREE=7
32
33
34
35 #Clear the logs if the script is executed second time
36
37 :> ${ERRORLOG}
38
39 :> ${ACTIVITYLOG}
40
41
42
43 ##Uploading the daily backup to Amazon s3
44
45 /usr/bin/s3cmd -r put ${SOURCE} s3://MClouds-757cf3e2e4/${DESTINATION}/ 1>>${ACTIVITYLOG} 2>>${ERRORLOG}
46
47 ret2=$?
48
49
50
51 ##Sent email alert
52
53 msg="BACKUP NOTIFICATION ALERT FROM `hostname`"
54
55
56
57 if [ $ret2 -eq 0 ];then
58
59 msg1="Amazon s3 Backup Uploaded Successfully"
60
61 else
62
63 msg1="Amazon s3 Backup Failed!!\n Check ${ERRORLOG} for more details"
64
65 fi
66
67 echo -e "$msg1"|mail -s "$msg" ${_EMAIL}
68
69
70
71 #######################
72
73 ##Deleting backup's older than DEGREE days
74
75 ## Delete from both server and amazon
76
77 #######################
78
79 DELETENAME=$(date --date="${DEGREE} days ago" +%F)
80
81
82
83 /usr/bin/s3cmd -r --force del s3://MClouds-757cf3e2e4/${DELETENAME} 1>>${ACTIVITYLOG} 2>>${ERRORLOG}
84
85
Cronjobs:
Daily Backup with 7 days retention:It takes daily full backup
35 10 * * * /root/s3cmdbackup.sh
Monthly Backup: It takes a full backup every month 15th and 28th dates
40 2 15,28 * * /root/s3cmdbackup.sh
Yearly backup: It takes a full backup every year december 31st
20 23 31 12 * /root/s3cmdbackup.sh
please post your comments below for site improvement
ReplyDelete