freedombone-backup-local 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Backup to local storage - typically a USB drive
  12. # License
  13. # =======
  14. #
  15. # Copyright (C) 2015-2016 Bob Mottram <bob@robotics.uk.to>
  16. #
  17. # This program is free software: you can redistribute it and/or modify
  18. # it under the terms of the GNU General Public License as published by
  19. # the Free Software Foundation, either version 3 of the License, or
  20. # (at your option) any later version.
  21. #
  22. # This program is distributed in the hope that it will be useful,
  23. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. # GNU General Public License for more details.
  26. #
  27. # You should have received a copy of the GNU General Public License
  28. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. PROJECT_NAME='freedombone'
  30. COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
  31. BACKUP_EXTRA_DIRECTORIES=/root/backup-extra-dirs.csv
  32. ENABLE_VERIFICATION="no"
  33. export TEXTDOMAIN=${PROJECT_NAME}-backup-local
  34. export TEXTDOMAINDIR="/usr/share/locale"
  35. USB_DRIVE=/dev/sdb1
  36. USB_MOUNT=/mnt/usb
  37. # get default USB from config file
  38. CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg
  39. if [ -f $CONFIG_FILE ]; then
  40. if grep -q "USB_DRIVE=" $CONFIG_FILE; then
  41. USB_DRIVE=$(cat $CONFIG_FILE | grep "USB_DRIVE=" | awk -F '=' '{print $2}')
  42. fi
  43. fi
  44. ADMIN_USERNAME=
  45. ADMIN_NAME=
  46. # The name of a currently suspended site
  47. # Sites are suspended so that verification should work
  48. SUSPENDED_SITE=
  49. DATABASE_PASSWORD=''
  50. if [ -f /root/dbpass ]; then
  51. DATABASE_PASSWORD=$(cat /root/dbpass)
  52. fi
  53. function suspend_site {
  54. # suspends a given website
  55. if [[ $ENABLE_VERIFICATION != "yes" ]]; then
  56. return
  57. fi
  58. SUSPENDED_SITE="$1"
  59. nginx_dissite $SUSPENDED_SITE
  60. service nginx reload
  61. }
  62. function restart_site {
  63. # restarts a given website
  64. if [ ! $SUSPENDED_SITE ]; then
  65. return
  66. fi
  67. nginx_ensite $SUSPENDED_SITE
  68. service nginx reload
  69. SUSPENDED_SITE=
  70. }
  71. function update_domains {
  72. GIT_DOMAIN_NAME='gogs'
  73. if grep -q "Gogs domain" $COMPLETION_FILE; then
  74. GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
  75. fi
  76. MICROBLOG_DOMAIN_NAME='microblog'
  77. if grep -q "GNU Social domain" $COMPLETION_FILE; then
  78. MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
  79. fi
  80. HUBZILLA_DOMAIN_NAME='hubzilla'
  81. if grep -q "Hubzilla domain" $COMPLETION_FILE; then
  82. HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
  83. fi
  84. FULLBLOG_DOMAIN_NAME='blog'
  85. if grep -q "Blog domain" $COMPLETION_FILE; then
  86. FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
  87. fi
  88. OWNCLOUD_DOMAIN_NAME='owncloud'
  89. if grep -q "Owncloud domain" $COMPLETION_FILE; then
  90. OWNCLOUD_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Owncloud domain" | awk -F ':' '{print $2}')
  91. fi
  92. }
  93. function mount_drive {
  94. if [ $1 ]; then
  95. USB_DRIVE=/dev/${1}1
  96. fi
  97. # get the admin user
  98. ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
  99. if [ $2 ]; then
  100. ADMIN_USERNAME=$2
  101. fi
  102. ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1)
  103. # check that the backup destination is available
  104. if [ ! -b $USB_DRIVE ]; then
  105. echo $"Please attach a USB drive"
  106. exit 1
  107. fi
  108. # unmount if already mounted
  109. umount -f $USB_MOUNT
  110. if [ ! -d $USB_MOUNT ]; then
  111. mkdir $USB_MOUNT
  112. fi
  113. if [ -f /dev/mapper/encrypted_usb ]; then
  114. rm -rf /dev/mapper/encrypted_usb
  115. fi
  116. cryptsetup luksClose encrypted_usb
  117. # mount the encrypted backup drive
  118. cryptsetup luksOpen $USB_DRIVE encrypted_usb
  119. if [ "$?" = "0" ]; then
  120. USB_DRIVE=/dev/mapper/encrypted_usb
  121. fi
  122. mount $USB_DRIVE $USB_MOUNT
  123. if [ ! "$?" = "0" ]; then
  124. echo $"There was a problem mounting the USB drive to $USB_MOUNT"
  125. rm -rf $USB_MOUNT
  126. exit 2
  127. fi
  128. }
  129. function unmount_drive {
  130. sync
  131. umount $USB_MOUNT
  132. if [ ! "$?" = "0" ]; then
  133. echo $"Unable to unmount the drive. This means that the backup did not work"
  134. rm -rf $USB_MOUNT
  135. exit 9
  136. fi
  137. rm -rf $USB_MOUNT
  138. if [[ $USB_DRIVE == /dev/mapper/encrypted_usb ]]; then
  139. echo $"Unmount encrypted USB"
  140. cryptsetup luksClose encrypted_usb
  141. fi
  142. if [ -f /dev/mapper/encrypted_usb ]; then
  143. rm -rf /dev/mapper/encrypted_usb
  144. fi
  145. echo $"Backup to USB drive is complete. You can now unplug it."
  146. }
  147. function backup_database {
  148. if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
  149. echo $"No MariaDB password was given"
  150. restart_site
  151. exit 10
  152. fi
  153. if [ ! -d $USB_MOUNT/backup/${1} ]; then
  154. mkdir -p $USB_MOUNT/backup/${1}
  155. fi
  156. if [ ! -d $USB_MOUNT/backup/${1}data ]; then
  157. mkdir -p $USB_MOUNT/backup/${1}data
  158. fi
  159. if [ ! -d /root/temp${1}data ]; then
  160. mkdir -p /root/temp${1}data
  161. fi
  162. echo $"Obtaining ${1} database backup"
  163. mysqldump --password="$DATABASE_PASSWORD" ${1} > /root/temp${1}data/${1}.sql
  164. if [ ! -s /root/temp${1}data/${1}.sql ]; then
  165. echo $"${1} database could not be saved"
  166. shred -zu /root/temp${1}data/*
  167. rm -rf /root/temp${1}data
  168. umount $USB_MOUNT
  169. rm -rf $USB_MOUNT
  170. restart_site
  171. exit 5
  172. fi
  173. }
  174. function backup_directory_to_usb {
  175. if [ ! -d ${1} ]; then
  176. echo $"WARNING: directory does not exist: ${1}"
  177. else
  178. BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)")
  179. if [ ! "$?" = "0" ]; then
  180. echo $"Backup key could not be found"
  181. restart_site
  182. exit 6
  183. fi
  184. MY_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
  185. if [ ! -d $USB_MOUNT/backup/${2} ]; then
  186. mkdir -p $USB_MOUNT/backup/${2}
  187. fi
  188. obnam force-lock -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
  189. obnam backup -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
  190. if [[ $ENABLE_VERIFICATION == "yes" ]]; then
  191. obnam verify -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
  192. if [ ! "$?" = "0" ]; then
  193. umount $USB_MOUNT
  194. rm -rf $USB_MOUNT
  195. if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
  196. shred -zu ${1}/*
  197. rm -rf ${1}
  198. fi
  199. restart_site
  200. exit 71
  201. fi
  202. fi
  203. obnam forget --keep=30d -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID
  204. if [ ! "$?" = "0" ]; then
  205. umount $USB_MOUNT
  206. rm -rf $USB_MOUNT
  207. if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
  208. shred -zu ${1}/*
  209. rm -rf ${1}
  210. fi
  211. restart_site
  212. exit 7
  213. fi
  214. if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
  215. shred -zu ${1}/*
  216. rm -rf ${1}
  217. fi
  218. fi
  219. }
  220. function make_backup_directory {
  221. # make a backup directory on the drive
  222. if [ ! -d $USB_MOUNT/backup ]; then
  223. mkdir $USB_MOUNT/backup
  224. fi
  225. if [ ! -d $USB_MOUNT/backup ]; then
  226. echo $"There was a problem making the directory $USB_MOUNT/backup."
  227. umount $USB_MOUNT
  228. rm -rf $USB_MOUNT
  229. exit 3
  230. fi
  231. }
  232. function check_storage_space_remaining {
  233. # Check space remaining on the usb drive
  234. used_percent=$(df -k $USB_MOUNT | tail -n 1 | awk -F ' ' '{print $5}' | awk -F '%' '{print $1}')
  235. if [ $used_percent -gt 95 ]; then
  236. echo $"Less than 5% of space remaining on backup drive"
  237. umount $USB_MOUNT
  238. rm -rf $USB_MOUNT
  239. exit 4
  240. fi
  241. }
  242. function backup_users {
  243. # Backup user files
  244. for d in /home/*/ ; do
  245. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  246. if [[ $USERNAME != "git" ]]; then
  247. # Backup any gpg keys
  248. if [ -d /home/$USERNAME/.gnupg ]; then
  249. echo $"Backing up gpg keys for $USERNAME"
  250. backup_directory_to_usb /home/$USERNAME/.gnupg gnupg/$USERNAME
  251. fi
  252. # Backup any personal settings
  253. if [ -d /home/$USERNAME/personal ]; then
  254. echo $"Backing up personal settings for $USERNAME"
  255. backup_directory_to_usb /home/$USERNAME/personal personal/$USERNAME
  256. fi
  257. # Backup ssh keys
  258. if [ -d /home/$USERNAME/.ssh ]; then
  259. echo $"Backing up ssh keys for $USERNAME"
  260. backup_directory_to_usb /home/$USERNAME/.ssh ssh/$USERNAME
  261. fi
  262. # Backup user configs
  263. if [ -d /home/$USERNAME/.config ]; then
  264. echo $"Backing up config files for $USERNAME"
  265. backup_directory_to_usb /home/$USERNAME/.config config/$USERNAME
  266. fi
  267. # Backup mutt
  268. if [ -f /home/$USERNAME/.muttrc ]; then
  269. echo $"Backing up Mutt settings for $USERNAME"
  270. if [ ! -d /home/$USERNAME/tempbackup ]; then
  271. mkdir -p /home/$USERNAME/tempbackup
  272. fi
  273. cp /home/$USERNAME/.muttrc /home/$USERNAME/tempbackup
  274. if [ -f /etc/Muttrc ]; then
  275. cp /etc/Muttrc /home/$USERNAME/tempbackup
  276. fi
  277. backup_directory_to_usb /home/$USERNAME/tempbackup mutt/$USERNAME
  278. fi
  279. # Backup email
  280. if [ -d /home/$USERNAME/Maildir ]; then
  281. echo $"Creating an email archive for $USERNAME"
  282. if [ ! -d /root/tempbackupemail/$USERNAME ]; then
  283. mkdir -p /root/tempbackupemail/$USERNAME
  284. fi
  285. tar -czvf /root/tempbackupemail/$USERNAME/maildir.tar.gz /home/$USERNAME/Maildir
  286. echo $"Backing up emails for $USERNAME"
  287. backup_directory_to_usb /root/tempbackupemail/$USERNAME mail/$USERNAME
  288. fi
  289. # Backup spamassassin
  290. if [ -d /home/$USERNAME/.spamassassin ]; then
  291. echo $"Backing up spamassassin settings for $USERNAME"
  292. backup_directory_to_usb /home/$USERNAME/.spamassassin spamassassin/$USERNAME
  293. fi
  294. # Backup procmail
  295. if [ -f /home/$USERNAME/.procmailrc ]; then
  296. echo $"Backing up procmail settings for $USERNAME"
  297. if [ ! -d /home/$USERNAME/tempbackup ]; then
  298. mkdir -p /home/$USERNAME/tempbackup
  299. fi
  300. cp /home/$USERNAME/.procmailrc /home/$USERNAME/tempbackup
  301. backup_directory_to_usb /home/$USERNAME/tempbackup procmail/$USERNAME
  302. fi
  303. fi
  304. done
  305. }
  306. function backup_directories {
  307. # directories to be backed up (source,dest)
  308. backup_dirs=(
  309. "none, none, /etc/letsencrypt, letsencrypt"
  310. "none, none, /var/lib/dokuwiki, wiki"
  311. "none, none, /etc/dokuwiki, wiki2"
  312. "none, none, /etc/ssl, ssl"
  313. "none, none, /var/spool/mlmmj, mailinglist"
  314. "none, none, /var/lib/prosody, xmpp"
  315. "none, none, /etc/nginx/sites-available, web"
  316. "none, none, /home/$ADMIN_USERNAME/.ipfs, ipfs"
  317. "none, none, /var/cache/minidlna, dlna"
  318. "/etc/owncloud, owncloud, /root/tempownclouddata, ownclouddata"
  319. "none, none, /var/lib/owncloud, owncloud"
  320. "none, none, /etc/owncloud, owncloud2"
  321. "/home/git/go/src/github.com/gogits, gogs, /root/tempgogsdata, gogsdata"
  322. "none, none, /home/git/go/src/github.com/gogits/gogs/custom, gogs"
  323. "none, none, /home/git/gogs-repositories, gogsrepos"
  324. "none, none, /home/git/.ssh, gogsssh"
  325. "none, none, /var/lib/tox-bootstrapd, tox"
  326. "/var/www/${MICROBLOG_DOMAIN_NAME}, gnusocial, /root/tempgnusocialdata, gnusocialdata"
  327. "none, none, /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs, gnusocial"
  328. "/var/www/${HUBZILLA_DOMAIN_NAME}, hubzilla, /root/temphubzilladata, hubzilladata"
  329. "none, none, /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs, hubzilla"
  330. "none, none, /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs, blog"
  331. "none, none, /var/lib/tor, tor"
  332. )
  333. for dr in "${backup_dirs[@]}"
  334. do
  335. # if this directory exists then backup the given database
  336. required_directory=$(echo $dr | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
  337. database_name=$(echo $dr | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
  338. if [[ "$database_name" == *"hubzilla"* ]]; then
  339. suspend_site ${HUBZILLA_DOMAIN_NAME}
  340. fi
  341. if [[ "$database_name" == *"gnusocial"* ]]; then
  342. suspend_site ${MICROBLOG_DOMAIN_NAME}
  343. fi
  344. if [[ "$database_name" == *"owncloud"* ]]; then
  345. suspend_site ${OWNCLOUD_DOMAIN_NAME}
  346. fi
  347. if [[ "$database_name" == *"gogs"* ]]; then
  348. suspend_site ${GIT_DOMAIN_NAME}
  349. fi
  350. if [[ $required_directory != "none" ]]; then
  351. if [ -d $required_directory ]; then
  352. if [[ $database_name != "none" ]]; then
  353. backup_database $database_name
  354. fi
  355. fi
  356. fi
  357. # if this directory exists then back it up to the given destination
  358. source_directory=$(echo $dr | awk -F ',' '{print $3}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
  359. if [ -d $source_directory ]; then
  360. dest_directory=$(echo $dr | awk -F ',' '{print $4}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
  361. echo $"Backing up $source_directory to $dest_directory"
  362. backup_directory_to_usb $source_directory $dest_directory
  363. fi
  364. restart_site
  365. done
  366. }
  367. function remove_backup_directory {
  368. if [ $1 ]; then
  369. if [[ $1 == "remove" ]]; then
  370. if [ -d $USB_MOUNT/backup ]; then
  371. rm -rf $USB_MOUNT/backup
  372. echo $'Existing backup directory removed'
  373. unmount_drive
  374. exit 0
  375. fi
  376. fi
  377. fi
  378. }
  379. function prepare_directories {
  380. # Some miscellaneous preparation for backing up directories
  381. if [ -d /home/git/go/src/github.com/gogits ]; then
  382. mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/$ADMIN_USERNAME
  383. fi
  384. if [ -d /var/lib/tox-bootstrapd ]; then
  385. cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
  386. if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
  387. rm -rf /var/lib/tox-bootstrapd/Maildir
  388. fi
  389. fi
  390. }
  391. function backup_configuration {
  392. echo $"Backing up ${PROJECT_NAME} configuration files"
  393. if [ ! -d /root/tempbackupconfig ]; then
  394. mkdir -p /root/tempbackupconfig
  395. fi
  396. cp -f $CONFIG_FILE /root/tempbackupconfig
  397. cp -f $COMPLETION_FILE /root/tempbackupconfig
  398. if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then
  399. cp -f $BACKUP_EXTRA_DIRECTORIES /root/tempbackupconfig
  400. fi
  401. backup_directory_to_usb /root/tempbackupconfig config
  402. }
  403. function backup_admin_readme {
  404. if [ -f /home/$ADMIN_USERNAME/README ]; then
  405. echo $"Backing up README"
  406. if [ ! -d /home/$ADMIN_USERNAME/tempbackup ]; then
  407. mkdir -p /home/$ADMIN_USERNAME/tempbackup
  408. fi
  409. cp -f /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/tempbackup
  410. backup_directory_to_usb /home/$ADMIN_USERNAME/tempbackup readme
  411. fi
  412. }
  413. function backup_voip {
  414. if [ -f /etc/mumble-server.ini ]; then
  415. echo $"Backing up VoIP settings"
  416. if [ ! -d /root/tempvoipbackup ]; then
  417. mkdir -p /root/tempvoipbackup
  418. fi
  419. cp -f /etc/mumble-server.ini /root/tempvoipbackup
  420. cp -f /var/lib/mumble-server/mumble-server.sqlite /root/tempvoipbackup
  421. cp -f /etc/sipwitch.conf /root/tempvoipbackup
  422. backup_directory_to_usb /root/tempvoipbackup voip
  423. fi
  424. }
  425. function backup_mariadb {
  426. if [ ${#DATABASE_PASSWORD} -gt 1 ]; then
  427. if [ ! -d /root/tempmariadb ]; then
  428. mkdir /root/tempmariadb
  429. fi
  430. mysqldump --password="$DATABASE_PASSWORD" mysql user > /root/tempmariadb/mysql.sql
  431. if [ ! -s /root/tempmariadb/mysql.sql ]; then
  432. echo $"Unable to backup mysql settings"
  433. rm -rf /root/tempmariadb
  434. umount $USB_MOUNT
  435. rm -rf $USB_MOUNT
  436. exit 8
  437. fi
  438. echo "$DATABASE_PASSWORD" > /root/tempmariadb/db
  439. chmod 400 /root/tempmariadb/db
  440. backup_directory_to_usb /root/tempmariadb mariadb
  441. fi
  442. }
  443. function valid_backup_destination {
  444. destination_dir="$1"
  445. is_valid="yes"
  446. if [[ "$destination_dir" == "hubzilla" || \
  447. "$destination_dir" == "hubzilladata" || \
  448. "$destination_dir" == "gogs" || \
  449. "$destination_dir" == "gogsrepos" || \
  450. "$destination_dir" == "gogsssh" || \
  451. "$destination_dir" == "gnusocial" || \
  452. "$destination_dir" == "gnusocialdata" || \
  453. "$destination_dir" == "mariadb" || \
  454. "$destination_dir" == "config" || \
  455. "$destination_dir" == "letsencrypt" || \
  456. "$destination_dir" == "wiki" || \
  457. "$destination_dir" == "wiki2" || \
  458. "$destination_dir" == "xmpp" || \
  459. "$destination_dir" == "ipfs" || \
  460. "$destination_dir" == "dlna" || \
  461. "$destination_dir" == "tox" || \
  462. "$destination_dir" == "ssl" || \
  463. "$destination_dir" == "blog" || \
  464. "$destination_dir" == "owncloud" || \
  465. "$destination_dir" == "owncloud2" || \
  466. "$destination_dir" == "ownclouddata" || \
  467. "$destination_dir" == "mailinglist" ]]; then
  468. is_valid="no"
  469. fi
  470. echo $is_valid
  471. }
  472. function backup_extra_directories {
  473. if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then
  474. return
  475. fi
  476. echo $"Backing up some additional directories"
  477. while read backup_line
  478. do
  479. backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
  480. if [ -d "$backup_dir" ]; then
  481. destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
  482. if [[ $(valid_backup_destination "$destination_dir") == "yes" ]]; then
  483. backup_directory_to_usb "$backup_dir" "$destination_dir"
  484. else
  485. echo $"WARNING: The backup directory $destination_dir is already used."
  486. echo $"Choose a different destination name for backing up $backup_dir"
  487. fi
  488. else
  489. echo $"WARNING: Directory $backup_dir does not exist"
  490. fi
  491. done <$BACKUP_EXTRA_DIRECTORIES
  492. }
  493. # has the remove option been set ?
  494. remove_option=$2
  495. if [[ $1 == "remove" ]]; then
  496. remove_option=$1
  497. fi
  498. mount_drive $1 $2
  499. remove_backup_directory $remove_option
  500. make_backup_directory
  501. check_storage_space_remaining
  502. update_domains
  503. backup_users
  504. prepare_directories
  505. backup_directories
  506. backup_configuration
  507. backup_admin_readme
  508. backup_voip
  509. backup_mariadb
  510. backup_extra_directories
  511. unmount_drive
  512. exit 0