Kaynağa Gözat

Suspend sites while backing up

This avoids backup verification failures
Bob Mottram 9 yıl önce
ebeveyn
işleme
91a670f11b
2 değiştirilmiş dosya ile 87 ekleme ve 2 silme
  1. 50
    1
      src/freedombone-backup-local
  2. 37
    1
      src/freedombone-backup-remote

+ 50
- 1
src/freedombone-backup-local Dosyayı Görüntüle

@@ -49,13 +49,37 @@ fi
49 49
 ADMIN_USERNAME=
50 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 56
 DATABASE_PASSWORD=''
53 57
 if [ -f /root/dbpass ]; then
54 58
     DATABASE_PASSWORD=$(cat /root/dbpass)
55 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 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 83
     MICROBLOG_DOMAIN_NAME='microblog'
60 84
     if grep -q "GNU Social domain" $COMPLETION_FILE; then
61 85
         MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
@@ -68,6 +92,10 @@ function update_domains {
68 92
     if grep -q "Blog domain" $COMPLETION_FILE; then
69 93
         FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
70 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 101
 function mount_drive {
@@ -133,6 +161,7 @@ function unmount_drive {
133 161
 function backup_database {
134 162
     if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
135 163
         echo $"No MariaDB password was given"
164
+        restart_site
136 165
         exit 10
137 166
     fi
138 167
     if [ ! -d $USB_MOUNT/backup/${1} ]; then
@@ -152,6 +181,7 @@ function backup_database {
152 181
         rm -rf /root/temp${1}data
153 182
         umount $USB_MOUNT
154 183
         rm -rf $USB_MOUNT
184
+        restart_site
155 185
         exit 5
156 186
     fi
157 187
 }
@@ -163,6 +193,7 @@ function backup_directory_to_usb {
163 193
         BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)")
164 194
         if [ ! "$?" = "0" ]; then
165 195
             echo $"Backup key could not be found"
196
+            restart_site
166 197
             exit 6
167 198
         fi
168 199
         MY_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
@@ -179,6 +210,7 @@ function backup_directory_to_usb {
179 210
                 shred -zu ${1}/*
180 211
                 rm -rf ${1}
181 212
             fi
213
+            restart_site
182 214
             exit 71
183 215
         fi
184 216
         obnam forget --keep=30d -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID
@@ -189,6 +221,7 @@ function backup_directory_to_usb {
189 221
                 shred -zu ${1}/*
190 222
                 rm -rf ${1}
191 223
             fi
224
+            restart_site
192 225
             exit 7
193 226
         fi
194 227
         if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
@@ -326,9 +359,23 @@ function backup_directories {
326 359
     do
327 360
         # if this directory exists then backup the given database
328 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 377
         if [[ $required_directory != "none" ]]; then
330 378
             if [ -d $required_directory ]; then
331
-                database_name=$(echo $dr | awk -F ',' '{print $2}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
332 379
                 if [[ $database_name != "none" ]]; then
333 380
                     backup_database $database_name
334 381
                 fi
@@ -342,6 +389,8 @@ function backup_directories {
342 389
             echo $"Backing up $source_directory to $dest_directory"
343 390
             backup_directory_to_usb $source_directory $dest_directory
344 391
         fi
392
+
393
+        restart_site
345 394
     done
346 395
 }
347 396
 

+ 37
- 1
src/freedombone-backup-remote Dosyayı Görüntüle

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