-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample
136 lines (108 loc) · 4.14 KB
/
example
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
#
# Copyright (C) 2013 Dan Fruehauf <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# initiate logging modules
# you may specify multiple logging destinations, it's all good :)
log() {
# log to a log file at /var/log/backups/backups.log
logfile /var/log/backups/backups.log
# log to another log file at /var/log/backups/backups2.log
logfile /var/log/backups/backups2.log
# log to syslog facility local0
syslog local0
}
# actual objects for backup
# this will dump everything to a temporary directory
backup() {
# copy contents of /etc/backup-dir-1 to backup context (sub directory)
# backup-dir-1
rsync backup-dir-1 /etc/backup-dir-1
# copy root@piglet:/etc to piglet backup
rsync piglet root@piglet:/etc
# and add piglet:/var to piglet backup
rsync piglet root@piglet:/var
# make an archive out of a bunch of files
tar cow /etc/passwd /etc/sysconfig/kernel
# make an archive using sudo
tar cow --sudo /etc/passwd /etc/sysconfig/kernel
# make an archive using sudo with some excludes
tar cow /etc --exclude=/etc/passwd
# backup a pgsql database
# the tuple below is:
# HOSTNAME:PORT:DB:USERNAME:PASSWORD
pgsql zebra africa:5432:lions_domain:lion:hyena
# backup a mysql database, pretty simple to the pgsql one
mysql zebra africa:3306:lions_domain:lion:hyena
# it is possible to also just run commands in this section
execute mount -o remount,ro /var
}
# post processing of backup
# add here compressoin, encryption, what not...
process() {
# gzip all files in this backup
# quote the regular expression, especially if it contains a * :)
gzip '.*'
# use bz2 to compress all jpg files
bzip2 '.*\.jpg$'
# use xz to compress all cpp files
xz '.*\.cpp$'
# encrypt all files ending with .sh with a gpg key located at
# /home/john/john-gpg-key.asc
gpg '.*\.sh$' /home/john/john-gpg-key.asc
# split files into smaller chunks
# split all files ('.*') into 5mb chunks, size is given in bytes
split '.*' 5000000
}
# store the backup
# this will copy the temporary directory we backed into to other locations
store() {
# copy backup locally to /var/backups
cp /var/backups
# alternatively, one could use mv, however this must be the last store
# operation as it will remove the backup from its place
mv /var/backups
# cycle local backups, leaving only the 2 latest backups
cycle /var/backups 2
# store with scp crapper:/var/backups, with context name backy
# using key at ~/.ssh/id_rsa
# password authentication is not support, use key exchange if you need
# scp backups
scp backy root@crapper:/var/backups -i ~/.ssh/id_rsa
# store backup on Amazon S3 in bucket 'cake'
s3 cake --access_key=AWS_ACCESS_KEY --secret_key=AWS_SECRET_KEY
# leave the last 3 backups in the 'cake' S3 bucket
s3_cycle cake 3 --access_key=AWS_ACCESS_KEY --secret_key=AWS_SECRET_KEY
}
# notifications of backup status
notify() {
# notify via email
# send to [email protected]
email [email protected]
# send to [email protected], using smtp server mail.mail.com,port 25
email [email protected] mail.mail.com 25
# notify via nagios NSCA
# first parameter is the nagios monitor name, the rest of the parameters
# will just be passed to the send_nsca binary
nagios_nsca "backup monitor" -H nagios.emii.org.au
# write status to file using nagios format
# will write status to /var/log/backup/status/BACKUP_MODEL_NAME
nagios_status /var/log/backup/status/
# notify via pushover, implemented with curl
# you'll just have to specify the user token and app token
pushover USER_TOKEN APP_TOKEN
}