freedombone-backup-local 21KB

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