浏览代码

Suspend sites while backing up

This avoids backup verification failures
Bob Mottram 9 年前
父节点
当前提交
91a670f11b
共有 2 个文件被更改,包括 87 次插入2 次删除
  1. 50
    1
      src/freedombone-backup-local
  2. 37
    1
      src/freedombone-backup-remote

+ 50
- 1
src/freedombone-backup-local 查看文件

49
 ADMIN_USERNAME=
49
 ADMIN_USERNAME=
50
 ADMIN_NAME=
50
 ADMIN_NAME=
51
 
51
 
52
+# The name of a currently suspended site
53
+# Sites are suspended so that verification should work
54
+SUSPENDED_SITE=
55
+
52
 DATABASE_PASSWORD=''
56
 DATABASE_PASSWORD=''
53
 if [ -f /root/dbpass ]; then
57
 if [ -f /root/dbpass ]; then
54
     DATABASE_PASSWORD=$(cat /root/dbpass)
58
     DATABASE_PASSWORD=$(cat /root/dbpass)
55
 fi
59
 fi
56
 
60
 
61
+function suspend_site {
62
+    # suspends a given website
63
+    SUSPENDED_SITE="$1"
64
+    nginx_dissite $SUSPENDED_SITE
65
+    service nginx reload
66
+}
67
+
68
+function restart_site {
69
+    # restarts a given website
70
+    if [ ! $SUSPENDED_SITE ]; then
71
+        return
72
+    fi
73
+    nginx_ensite $SUSPENDED_SITE
74
+    service nginx reload
75
+    SUSPENDED_SITE=
76
+}
57
 
77
 
58
 function update_domains {
78
 function update_domains {
79
+    GIT_DOMAIN_NAME='gogs'
80
+    if grep -q "Gogs domain" $COMPLETION_FILE; then
81
+        GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
82
+    fi
59
     MICROBLOG_DOMAIN_NAME='microblog'
83
     MICROBLOG_DOMAIN_NAME='microblog'
60
     if grep -q "GNU Social domain" $COMPLETION_FILE; then
84
     if grep -q "GNU Social domain" $COMPLETION_FILE; then
61
         MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
85
         MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
68
     if grep -q "Blog domain" $COMPLETION_FILE; then
92
     if grep -q "Blog domain" $COMPLETION_FILE; then
69
         FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
93
         FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
70
     fi
94
     fi
95
+    OWNCLOUD_DOMAIN_NAME='owncloud'
96
+    if grep -q "Owncloud domain" $COMPLETION_FILE; then
97
+        OWNCLOUD_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Owncloud domain" | awk -F ':' '{print $2}')
98
+    fi
71
 }
99
 }
72
 
100
 
73
 function mount_drive {
101
 function mount_drive {
133
 function backup_database {
161
 function backup_database {
134
     if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
162
     if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
135
         echo $"No MariaDB password was given"
163
         echo $"No MariaDB password was given"
164
+        restart_site
136
         exit 10
165
         exit 10
137
     fi
166
     fi
138
     if [ ! -d $USB_MOUNT/backup/${1} ]; then
167
     if [ ! -d $USB_MOUNT/backup/${1} ]; then
152
         rm -rf /root/temp${1}data
181
         rm -rf /root/temp${1}data
153
         umount $USB_MOUNT
182
         umount $USB_MOUNT
154
         rm -rf $USB_MOUNT
183
         rm -rf $USB_MOUNT
184
+        restart_site
155
         exit 5
185
         exit 5
156
     fi
186
     fi
157
 }
187
 }
163
         BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)")
193
         BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)")
164
         if [ ! "$?" = "0" ]; then
194
         if [ ! "$?" = "0" ]; then
165
             echo $"Backup key could not be found"
195
             echo $"Backup key could not be found"
196
+            restart_site
166
             exit 6
197
             exit 6
167
         fi
198
         fi
168
         MY_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
199
         MY_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
179
                 shred -zu ${1}/*
210
                 shred -zu ${1}/*
180
                 rm -rf ${1}
211
                 rm -rf ${1}
181
             fi
212
             fi
213
+            restart_site
182
             exit 71
214
             exit 71
183
         fi
215
         fi
184
         obnam forget --keep=30d -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID
216
         obnam forget --keep=30d -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID
189
                 shred -zu ${1}/*
221
                 shred -zu ${1}/*
190
                 rm -rf ${1}
222
                 rm -rf ${1}
191
             fi
223
             fi
224
+            restart_site
192
             exit 7
225
             exit 7
193
         fi
226
         fi
194
         if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
227
         if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
326
     do
359
     do
327
         # if this directory exists then backup the given database
360
         # if this directory exists then backup the given database
328
         required_directory=$(echo $dr | awk -F ',' '{print $1}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
361
         required_directory=$(echo $dr | awk -F ',' '{print $1}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
362
+        database_name=$(echo $dr | awk -F ',' '{print $2}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
363
+
364
+        if [[ "$database_name" == *"hubzilla"* ]]; then
365
+            suspend_site ${HUBZILLA_DOMAIN_NAME}
366
+        fi
367
+        if [[ "$database_name" == *"gnusocial"* ]]; then
368
+            suspend_site ${MICROBLOG_DOMAIN_NAME}
369
+        fi
370
+        if [[ "$database_name" == *"owncloud"* ]]; then
371
+            suspend_site ${OWNCLOUD_DOMAIN_NAME}
372
+        fi
373
+        if [[ "$database_name" == *"gogs"* ]]; then
374
+            suspend_site ${GIT_DOMAIN_NAME}
375
+        fi
376
+
329
         if [[ $required_directory != "none" ]]; then
377
         if [[ $required_directory != "none" ]]; then
330
             if [ -d $required_directory ]; then
378
             if [ -d $required_directory ]; then
331
-                database_name=$(echo $dr | awk -F ',' '{print $2}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
332
                 if [[ $database_name != "none" ]]; then
379
                 if [[ $database_name != "none" ]]; then
333
                     backup_database $database_name
380
                     backup_database $database_name
334
                 fi
381
                 fi
342
             echo $"Backing up $source_directory to $dest_directory"
389
             echo $"Backing up $source_directory to $dest_directory"
343
             backup_directory_to_usb $source_directory $dest_directory
390
             backup_directory_to_usb $source_directory $dest_directory
344
         fi
391
         fi
392
+
393
+        restart_site
345
     done
394
     done
346
 }
395
 }
347
 
396
 

+ 37
- 1
src/freedombone-backup-remote 查看文件

66
     mkdir -p $SERVER_DIRECTORY/backup
66
     mkdir -p $SERVER_DIRECTORY/backup
67
 fi
67
 fi
68
 
68
 
69
+# The name of a currently suspended site
70
+# Sites are suspended so that verification should work
71
+SUSPENDED_SITE=
72
+
73
+function suspend_site {
74
+    # suspends a given website
75
+    SUSPENDED_SITE="$1"
76
+    nginx_dissite $SUSPENDED_SITE
77
+    service nginx reload
78
+}
79
+
80
+function restart_site {
81
+    # restarts a given website
82
+    if [ ! $SUSPENDED_SITE ]; then
83
+        return
84
+    fi
85
+    nginx_ensite $SUSPENDED_SITE
86
+    service nginx reload
87
+    SUSPENDED_SITE=
88
+}
89
+
69
 function backup_directory_to_friend {
90
 function backup_directory_to_friend {
70
     BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)")
91
     BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)")
71
     if [ ! "$?" = "0" ]; then
92
     if [ ! "$?" = "0" ]; then
72
         echo $"Backup key could not be found"
93
         echo $"Backup key could not be found"
94
+        restart_site
73
         exit 43382
95
         exit 43382
74
     fi
96
     fi
75
     ADMIN_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
97
     ADMIN_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
86
         fi
108
         fi
87
         # Send a warning email
109
         # Send a warning email
88
         echo "Unable to verify ${2}" | mail -s "${PROJECT_NAME} backup to friends" ${ADMIN_EMAIL_ADDRESS}
110
         echo "Unable to verify ${2}" | mail -s "${PROJECT_NAME} backup to friends" ${ADMIN_EMAIL_ADDRESS}
111
+        restart_site
89
         exit 953
112
         exit 953
90
     fi
113
     fi
91
     obnam forget --keep=30d -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID}
114
     obnam forget --keep=30d -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID}
96
         fi
119
         fi
97
         # Send a warning email
120
         # Send a warning email
98
         echo "Unable to backup ${2}" | mail -s "${PROJECT_NAME} backup to friends" ${ADMIN_EMAIL_ADDRESS}
121
         echo "Unable to backup ${2}" | mail -s "${PROJECT_NAME} backup to friends" ${ADMIN_EMAIL_ADDRESS}
122
+        restart_site
99
         exit 853
123
         exit 853
100
     fi
124
     fi
101
     if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
125
     if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
107
 function backup_database_to_friend {
131
 function backup_database_to_friend {
108
     if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
132
     if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
109
         echo $"No MariaDB password was given"
133
         echo $"No MariaDB password was given"
134
+        restart_site
110
         exit 5783
135
         exit 5783
111
     fi
136
     fi
112
     if [ ! -d $SERVER_DIRECTORY/backup/${1} ]; then
137
     if [ ! -d $SERVER_DIRECTORY/backup/${1} ]; then
126
         rm -rf /root/temp${1}data
151
         rm -rf /root/temp${1}data
127
         # Send a warning email
152
         # Send a warning email
128
         echo $"Unable to export ${1} database" | mail -s $"${PROJECT_NAME} backup to friends" $ADMIN_EMAIL_ADDRESS
153
         echo $"Unable to export ${1} database" | mail -s $"${PROJECT_NAME} backup to friends" $ADMIN_EMAIL_ADDRESS
154
+        restart_site
129
         exit 5738
155
         exit 5738
130
     fi
156
     fi
131
 }
157
 }
226
     if grep -q "GNU Social domain" $COMPLETION_FILE; then
252
     if grep -q "GNU Social domain" $COMPLETION_FILE; then
227
         MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
253
         MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
228
         if [ -d /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs ]; then
254
         if [ -d /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs ]; then
255
+            suspend_site ${MICROBLOG_DOMAIN_NAME}
229
             backup_database_to_friend gnusocial
256
             backup_database_to_friend gnusocial
230
             backup_directory_to_friend /root/tempgnusocialdata gnusocialdata
257
             backup_directory_to_friend /root/tempgnusocialdata gnusocialdata
231
             echo $"Backing up GNU social installation"
258
             echo $"Backing up GNU social installation"
232
             backup_directory_to_friend /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs gnusocial
259
             backup_directory_to_friend /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs gnusocial
260
+            restart_site
233
         else
261
         else
234
             echo $"GNU Social domain specified but not found in /var/www/${MICROBLOG_DOMAIN_NAME}"
262
             echo $"GNU Social domain specified but not found in /var/www/${MICROBLOG_DOMAIN_NAME}"
235
         fi
263
         fi
240
     if grep -q "Hubzilla domain" $COMPLETION_FILE; then
268
     if grep -q "Hubzilla domain" $COMPLETION_FILE; then
241
         HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
269
         HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
242
         if [ -d /var/www/${HUBZILLA_DOMAIN_NAME} ]; then
270
         if [ -d /var/www/${HUBZILLA_DOMAIN_NAME} ]; then
271
+            suspend_site ${HUBZILLA_DOMAIN_NAME}
243
             backup_database_to_friend hubzilla
272
             backup_database_to_friend hubzilla
244
             backup_directory_to_friend /root/temphubzilladata hubzilladata
273
             backup_directory_to_friend /root/temphubzilladata hubzilladata
245
             echo "Backing up Hubzilla installation"
274
             echo "Backing up Hubzilla installation"
246
             backup_directory_to_friend /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs hubzilla
275
             backup_directory_to_friend /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs hubzilla
276
+            restart_site
247
         else
277
         else
248
             echo $"Hubzilla domain specified but not found in /var/www/${HUBZILLA_DOMAIN_NAME}"
278
             echo $"Hubzilla domain specified but not found in /var/www/${HUBZILLA_DOMAIN_NAME}"
249
             exit 2578
279
             exit 2578
253
 
283
 
254
 function backup_owncloud {
284
 function backup_owncloud {
255
     if [ -d /etc/owncloud ]; then
285
     if [ -d /etc/owncloud ]; then
286
+        OWNCLOUD_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Owncloud domain" | awk -F ':' '{print $2}')
287
+        suspend_site ${OWNCLOUD_DOMAIN_NAME}
256
         backup_database_to_friend owncloud
288
         backup_database_to_friend owncloud
257
         backup_directory_to_friend /root/tempownclouddata ownclouddata
289
         backup_directory_to_friend /root/tempownclouddata ownclouddata
258
         echo $"Backing up Owncloud data"
290
         echo $"Backing up Owncloud data"
259
         backup_directory_to_friend /var/lib/owncloud owncloud
291
         backup_directory_to_friend /var/lib/owncloud owncloud
260
         backup_directory_to_friend /etc/owncloud owncloud2
292
         backup_directory_to_friend /etc/owncloud owncloud2
293
+        restart_site
261
     fi
294
     fi
262
 }
295
 }
263
 
296
 
264
 function backup_gogs {
297
 function backup_gogs {
265
     if [ -d /home/git/go/src/github.com/gogits ]; then
298
     if [ -d /home/git/go/src/github.com/gogits ]; then
299
+        GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
300
+        suspend_site ${GIT_DOMAIN_NAME}
266
         backup_database_to_friend gogs
301
         backup_database_to_friend gogs
267
         backup_directory_to_friend /root/tempgogsdata gogsdata
302
         backup_directory_to_friend /root/tempgogsdata gogsdata
268
         echo $"Obtaining Gogs settings backup"
303
         echo $"Obtaining Gogs settings backup"
272
         backup_directory_to_friend /home/git/gogs-repositories gogsrepos
307
         backup_directory_to_friend /home/git/gogs-repositories gogsrepos
273
         echo $"Obtaining Gogs authorized_keys backup"
308
         echo $"Obtaining Gogs authorized_keys backup"
274
         backup_directory_to_friend /home/git/.ssh gogsssh
309
         backup_directory_to_friend /home/git/.ssh gogsssh
310
+        restart_site
275
     fi
311
     fi
276
 }
312
 }
277
 
313
 
537
     if [ $REMOTE_SERVER ]; then
573
     if [ $REMOTE_SERVER ]; then
538
         REMOTE_DOMAIN=$(echo "${remote_server}" | awk -F ' ' '{print $1}' | awk -F '@' '{print $2}')
574
         REMOTE_DOMAIN=$(echo "${remote_server}" | awk -F ' ' '{print $1}' | awk -F '@' '{print $2}')
539
         REMOTE_SSH_PORT=$(echo "${remote_server}" | awk -F ' ' '{print $2}')
575
         REMOTE_SSH_PORT=$(echo "${remote_server}" | awk -F ' ' '{print $2}')
540
-		REMOTE_DIRECTORY=$(echo "${remote_server}" | awk -F ' ' '{print $3}')
576
+        REMOTE_DIRECTORY=$(echo "${remote_server}" | awk -F ' ' '{print $3}')
541
         REMOTE_PASSWORD=$(echo "${remote_server}" | awk -F ' ' '{print $4}')
577
         REMOTE_PASSWORD=$(echo "${remote_server}" | awk -F ' ' '{print $4}')
542
         NOW=$(date +"%Y-%m-%d %H:%M:%S")
578
         NOW=$(date +"%Y-%m-%d %H:%M:%S")
543
         REMOTE_SERVER=$REMOTE_SERVER:$REMOTE_DIRECTORY
579
         REMOTE_SERVER=$REMOTE_SERVER:$REMOTE_DIRECTORY