freedombone-backup-local 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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 fin database if it exists
  267. if [ -d /home/$USERNAME/.fin ]; then
  268. echo $"Backing up fin files for $USERNAME"
  269. backup_directory_to_usb /home/$USERNAME/.fin fin/$USERNAME
  270. fi
  271. # Backup user configs
  272. if [ -d /home/$USERNAME/.config ]; then
  273. echo $"Backing up config files for $USERNAME"
  274. backup_directory_to_usb /home/$USERNAME/.config config/$USERNAME
  275. fi
  276. # Backup user local
  277. if [ -d /home/$USERNAME/.local ]; then
  278. echo $"Backing up local files for $USERNAME"
  279. backup_directory_to_usb /home/$USERNAME/.local local/$USERNAME
  280. fi
  281. # Backup mutt
  282. if [ -f /home/$USERNAME/.muttrc ]; then
  283. echo $"Backing up Mutt settings for $USERNAME"
  284. if [ ! -d /home/$USERNAME/tempbackup ]; then
  285. mkdir -p /home/$USERNAME/tempbackup
  286. fi
  287. cp /home/$USERNAME/.muttrc /home/$USERNAME/tempbackup
  288. if [ -f /etc/Muttrc ]; then
  289. cp /etc/Muttrc /home/$USERNAME/tempbackup
  290. fi
  291. backup_directory_to_usb /home/$USERNAME/tempbackup mutt/$USERNAME
  292. fi
  293. # Backup email
  294. if [ -d /home/$USERNAME/Maildir ]; then
  295. echo $"Creating an email archive for $USERNAME"
  296. if [ ! -d /root/tempbackupemail/$USERNAME ]; then
  297. mkdir -p /root/tempbackupemail/$USERNAME
  298. fi
  299. tar -czvf /root/tempbackupemail/$USERNAME/maildir.tar.gz /home/$USERNAME/Maildir
  300. echo $"Backing up emails for $USERNAME"
  301. backup_directory_to_usb /root/tempbackupemail/$USERNAME mail/$USERNAME
  302. fi
  303. # Backup spamassassin
  304. if [ -d /home/$USERNAME/.spamassassin ]; then
  305. echo $"Backing up spamassassin settings for $USERNAME"
  306. backup_directory_to_usb /home/$USERNAME/.spamassassin spamassassin/$USERNAME
  307. fi
  308. # Backup procmail
  309. if [ -f /home/$USERNAME/.procmailrc ]; then
  310. echo $"Backing up procmail settings for $USERNAME"
  311. if [ ! -d /home/$USERNAME/tempbackup ]; then
  312. mkdir -p /home/$USERNAME/tempbackup
  313. fi
  314. cp /home/$USERNAME/.procmailrc /home/$USERNAME/tempbackup
  315. backup_directory_to_usb /home/$USERNAME/tempbackup procmail/$USERNAME
  316. fi
  317. fi
  318. done
  319. }
  320. function backup_directories {
  321. # directories to be backed up (source,dest)
  322. backup_dirs=(
  323. "none, none, /etc/letsencrypt, letsencrypt"
  324. "none, none, /var/lib/dokuwiki, wiki"
  325. "none, none, /etc/dokuwiki, wiki2"
  326. "none, none, /etc/ssl, ssl"
  327. "/etc/share/tt-rss, ttrss, /root/tempttrssdata, ttrss"
  328. "none, none, /var/spool/mlmmj, mailinglist"
  329. "none, none, /var/lib/prosody, xmpp"
  330. "none, none, /etc/nginx/sites-available, web"
  331. "none, none, /home/$ADMIN_USERNAME/.ipfs, ipfs"
  332. "none, none, /var/cache/minidlna, dlna"
  333. "/etc/owncloud, owncloud, /root/tempownclouddata, ownclouddata"
  334. "none, none, /var/lib/owncloud, owncloud"
  335. "none, none, /etc/owncloud, owncloud2"
  336. "/home/git/go/src/github.com/gogits, gogs, /root/tempgogsdata, gogsdata"
  337. "none, none, /home/git/go/src/github.com/gogits/gogs/custom, gogs"
  338. "none, none, /home/git/gogs-repositories, gogsrepos"
  339. "none, none, /home/git/.ssh, gogsssh"
  340. "none, none, /var/lib/tox-bootstrapd, tox"
  341. "/var/www/${MICROBLOG_DOMAIN_NAME}, gnusocial, /root/tempgnusocialdata, gnusocialdata"
  342. "none, none, /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs, gnusocial"
  343. "/var/www/${HUBZILLA_DOMAIN_NAME}, hubzilla, /root/temphubzilladata, hubzilladata"
  344. "none, none, /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs, hubzilla"
  345. "none, none, /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs, blog"
  346. "none, none, /var/lib/tor, tor"
  347. )
  348. for dr in "${backup_dirs[@]}"
  349. do
  350. # if this directory exists then backup the given database
  351. required_directory=$(echo $dr | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
  352. database_name=$(echo $dr | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
  353. if [[ "$database_name" == *"hubzilla"* ]]; then
  354. suspend_site ${HUBZILLA_DOMAIN_NAME}
  355. fi
  356. if [[ "$database_name" == *"gnusocial"* ]]; then
  357. suspend_site ${MICROBLOG_DOMAIN_NAME}
  358. fi
  359. if [[ "$database_name" == *"owncloud"* ]]; then
  360. suspend_site ${OWNCLOUD_DOMAIN_NAME}
  361. fi
  362. if [[ "$database_name" == *"gogs"* ]]; then
  363. suspend_site ${GIT_DOMAIN_NAME}
  364. fi
  365. if [[ "$database_name" == *"ttrss"* ]]; then
  366. suspend_site ${RSS_READER_DOMAIN_NAME}
  367. fi
  368. if [[ $required_directory != "none" ]]; then
  369. if [ -d $required_directory ]; then
  370. if [[ $database_name != "none" ]]; then
  371. backup_database $database_name
  372. fi
  373. fi
  374. fi
  375. # if this directory exists then back it up to the given destination
  376. source_directory=$(echo $dr | awk -F ',' '{print $3}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
  377. if [ -d $source_directory ]; then
  378. dest_directory=$(echo $dr | awk -F ',' '{print $4}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
  379. echo $"Backing up $source_directory to $dest_directory"
  380. backup_directory_to_usb $source_directory $dest_directory
  381. fi
  382. restart_site
  383. done
  384. }
  385. function remove_backup_directory {
  386. if [ $1 ]; then
  387. if [[ $1 == "remove" ]]; then
  388. if [ -d $USB_MOUNT/backup ]; then
  389. rm -rf $USB_MOUNT/backup
  390. echo $'Existing backup directory removed'
  391. unmount_drive
  392. exit 0
  393. fi
  394. fi
  395. fi
  396. }
  397. function prepare_directories {
  398. # Some miscellaneous preparation for backing up directories
  399. if [ -d /home/git/go/src/github.com/gogits ]; then
  400. mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/$ADMIN_USERNAME
  401. fi
  402. if [ -d /var/lib/tox-bootstrapd ]; then
  403. cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
  404. if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
  405. rm -rf /var/lib/tox-bootstrapd/Maildir
  406. fi
  407. fi
  408. }
  409. function backup_configuration {
  410. echo $"Backing up ${PROJECT_NAME} configuration files"
  411. if [ ! -d /root/tempbackupconfig ]; then
  412. mkdir -p /root/tempbackupconfig
  413. fi
  414. cp -f $CONFIG_FILE /root/tempbackupconfig
  415. cp -f $COMPLETION_FILE /root/tempbackupconfig
  416. if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then
  417. cp -f $BACKUP_EXTRA_DIRECTORIES /root/tempbackupconfig
  418. fi
  419. # nginx password hashes
  420. if [ -f /etc/nginx/.htpasswd ]; then
  421. cp -f /etc/nginx/.htpasswd /root/tempbackupconfig/htpasswd
  422. fi
  423. backup_directory_to_usb /root/tempbackupconfig config
  424. }
  425. function backup_admin_readme {
  426. if [ -f /home/$ADMIN_USERNAME/README ]; then
  427. echo $"Backing up README"
  428. if [ ! -d /home/$ADMIN_USERNAME/tempbackup ]; then
  429. mkdir -p /home/$ADMIN_USERNAME/tempbackup
  430. fi
  431. cp -f /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/tempbackup
  432. backup_directory_to_usb /home/$ADMIN_USERNAME/tempbackup readme
  433. fi
  434. }
  435. function backup_voip {
  436. if [ -f /etc/mumble-server.ini ]; then
  437. echo $"Backing up VoIP settings"
  438. if [ ! -d /root/tempvoipbackup ]; then
  439. mkdir -p /root/tempvoipbackup
  440. fi
  441. cp -f /etc/mumble-server.ini /root/tempvoipbackup
  442. cp -f /var/lib/mumble-server/mumble-server.sqlite /root/tempvoipbackup
  443. cp -f /etc/sipwitch.conf /root/tempvoipbackup
  444. backup_directory_to_usb /root/tempvoipbackup voip
  445. fi
  446. }
  447. function backup_mariadb {
  448. if [ ${#DATABASE_PASSWORD} -gt 1 ]; then
  449. if [ ! -d /root/tempmariadb ]; then
  450. mkdir /root/tempmariadb
  451. fi
  452. mysqldump --password="$DATABASE_PASSWORD" mysql user > /root/tempmariadb/mysql.sql
  453. if [ ! -s /root/tempmariadb/mysql.sql ]; then
  454. echo $"Unable to backup mysql settings"
  455. rm -rf /root/tempmariadb
  456. umount $USB_MOUNT
  457. rm -rf $USB_MOUNT
  458. exit 8
  459. fi
  460. echo "$DATABASE_PASSWORD" > /root/tempmariadb/db
  461. chmod 400 /root/tempmariadb/db
  462. backup_directory_to_usb /root/tempmariadb mariadb
  463. fi
  464. }
  465. function valid_backup_destination {
  466. destination_dir="$1"
  467. is_valid="yes"
  468. if [[ "$destination_dir" == "hubzilla" || \
  469. "$destination_dir" == "hubzilladata" || \
  470. "$destination_dir" == "gogs" || \
  471. "$destination_dir" == "gogsrepos" || \
  472. "$destination_dir" == "gogsssh" || \
  473. "$destination_dir" == "gnusocial" || \
  474. "$destination_dir" == "gnusocialdata" || \
  475. "$destination_dir" == "mariadb" || \
  476. "$destination_dir" == "config" || \
  477. "$destination_dir" == "letsencrypt" || \
  478. "$destination_dir" == "wiki" || \
  479. "$destination_dir" == "wiki2" || \
  480. "$destination_dir" == "xmpp" || \
  481. "$destination_dir" == "ipfs" || \
  482. "$destination_dir" == "dlna" || \
  483. "$destination_dir" == "tox" || \
  484. "$destination_dir" == "ssl" || \
  485. "$destination_dir" == "ttrss" || \
  486. "$destination_dir" == "blog" || \
  487. "$destination_dir" == "owncloud" || \
  488. "$destination_dir" == "owncloud2" || \
  489. "$destination_dir" == "ownclouddata" || \
  490. "$destination_dir" == "mailinglist" ]]; then
  491. is_valid="no"
  492. fi
  493. echo $is_valid
  494. }
  495. function backup_extra_directories {
  496. if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then
  497. return
  498. fi
  499. echo $"Backing up some additional directories"
  500. while read backup_line
  501. do
  502. backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
  503. if [ -d "$backup_dir" ]; then
  504. destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
  505. if [[ $(valid_backup_destination "$destination_dir") == "yes" ]]; then
  506. backup_directory_to_usb "$backup_dir" "$destination_dir"
  507. else
  508. echo $"WARNING: The backup directory $destination_dir is already used."
  509. echo $"Choose a different destination name for backing up $backup_dir"
  510. fi
  511. else
  512. echo $"WARNING: Directory $backup_dir does not exist"
  513. fi
  514. done <$BACKUP_EXTRA_DIRECTORIES
  515. }
  516. # has the remove option been set ?
  517. remove_option=$2
  518. if [[ $1 == "remove" ]]; then
  519. remove_option=$1
  520. fi
  521. mount_drive $1 $2
  522. remove_backup_directory $remove_option
  523. make_backup_directory
  524. check_storage_space_remaining
  525. update_domains
  526. backup_users
  527. prepare_directories
  528. backup_directories
  529. backup_configuration
  530. backup_admin_readme
  531. backup_voip
  532. backup_mariadb
  533. backup_extra_directories
  534. unmount_drive
  535. exit 0