freedombone-backup-remote 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Backup to remote servers - the web of backups
  12. # License
  13. # =======
  14. #
  15. # Copyright (C) 2015 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. CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg
  32. BACKUP_EXTRA_DIRECTORIES=/root/backup-extra-dirs.csv
  33. export TEXTDOMAIN=${PROJECT_NAME}-backup-remote
  34. export TEXTDOMAINDIR="/usr/share/locale"
  35. # Temporary location for data to be backed up to other servers
  36. SERVER_DIRECTORY=/root/remotebackup
  37. ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
  38. ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1)
  39. ADMIN_EMAIL_ADDRESS=${ADMIN_USERNAME}@${HOSTNAME}
  40. if [ ! -f /etc/ssl/private/backup.key ]; then
  41. echo $"Creating backup key"
  42. ${PROJECT_NAME}-addcert -h backup --dhkey 2048
  43. fi
  44. if [ ! -f /home/${ADMIN_USERNAME}/backup.list ]; then
  45. exit 1
  46. fi
  47. # MariaDB password
  48. DATABASE_PASSWORD=''
  49. if [ -f /root/dbpass ]; then
  50. DATABASE_PASSWORD=$(cat /root/dbpass)
  51. fi
  52. # local directory where the backup will be made
  53. if [ ! -d $SERVER_DIRECTORY ]; then
  54. mkdir $SERVER_DIRECTORY
  55. fi
  56. if [ ! -d $SERVER_DIRECTORY/backup ]; then
  57. mkdir -p $SERVER_DIRECTORY/backup
  58. fi
  59. function backup_directory_to_friend {
  60. BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)")
  61. if [ ! "$?" = "0" ]; then
  62. echo $"Backup key could not be found"
  63. exit 43382
  64. fi
  65. ADMIN_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
  66. if [ ! -d $SERVER_DIRECTORY/backup/${2} ]; then
  67. mkdir -p $SERVER_DIRECTORY/backup/${2}
  68. fi
  69. obnam force-lock -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} ${1}
  70. obnam backup -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} ${1}
  71. obnam verify -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} ${1}
  72. if [ ! "$?" = "0" ]; then
  73. if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
  74. shred -zu /root/temp${2}/*
  75. rm -rf /root/temp${2}
  76. fi
  77. # Send a warning email
  78. echo "Unable to verify ${2}" | mail -s "${PROJECT_NAME} backup to friends" ${ADMIN_EMAIL_ADDRESS}
  79. exit 953
  80. fi
  81. obnam forget --keep=30d -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID}
  82. if [ ! "$?" = "0" ]; then
  83. if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
  84. shred -zu /root/temp${2}/*
  85. rm -rf /root/temp${2}
  86. fi
  87. # Send a warning email
  88. echo "Unable to backup ${2}" | mail -s "${PROJECT_NAME} backup to friends" ${ADMIN_EMAIL_ADDRESS}
  89. exit 853
  90. fi
  91. if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
  92. shred -zu /root/temp${2}/*
  93. rm -rf /root/temp${2}
  94. fi
  95. }
  96. function backup_database_to_friend {
  97. if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
  98. echo $"No MariaDB password was given"
  99. exit 5783
  100. fi
  101. if [ ! -d $SERVER_DIRECTORY/backup/${1} ]; then
  102. mkdir -p $SERVER_DIRECTORY/backup/${1}
  103. fi
  104. if [ ! -d $SERVER_DIRECTORY/backup/${1}data ]; then
  105. mkdir -p $SERVER_DIRECTORY/backup/${1}data
  106. fi
  107. if [ ! -d /root/temp${1}data ]; then
  108. mkdir -p /root/temp${1}data
  109. fi
  110. echo "Obtaining ${1} database backup"
  111. mysqldump --password=$DATABASE_PASSWORD ${1} > /root/temp${1}data/${1}.sql
  112. if [ ! -s /root/temp${1}data/${1}.sql ]; then
  113. echo $"${1} database could not be saved"
  114. shred -zu /root/temp${1}data/*
  115. rm -rf /root/temp${1}data
  116. # Send a warning email
  117. echo $"Unable to export ${1} database" | mail -s $"${PROJECT_NAME} backup to friends" $ADMIN_EMAIL_ADDRESS
  118. exit 5738
  119. fi
  120. }
  121. function backup_configuration {
  122. echo $"Backing up ${PROJECT_NAME} configuration files"
  123. if [ ! -d /root/tempbackupconfig ]; then
  124. mkdir -p /root/tempbackupconfig
  125. fi
  126. cp -f $CONFIG_FILE /root/tempbackupconfig
  127. cp -f $COMPLETION_FILE /root/tempbackupconfig
  128. if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then
  129. cp -f $BACKUP_EXTRA_DIRECTORIES /root/tempbackupconfig
  130. fi
  131. backup_directory_to_friend /root/tempbackupconfig config
  132. }
  133. function backup_users {
  134. for d in /home/*/ ; do
  135. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  136. if [[ $USERNAME != "git" ]]; then
  137. # personal settings
  138. if [ -d /home/$USERNAME/personal ]; then
  139. echo $"Backing up personal settings for $USERNAME"
  140. backup_directory_to_friend /home/$USERNAME/personal personal/$USERNAME
  141. fi
  142. # gpg keys
  143. if [ -d /home/$USERNAME/.gnupg ]; then
  144. echo $"Backing up gpg keys for $USERNAME"
  145. backup_directory_to_friend /home/$USERNAME/.gnupg gnupg/$USERNAME
  146. fi
  147. # ssh keys
  148. if [ -d /home/$USERNAME/.ssh ]; then
  149. echo $"Backing up ssh keys for $USERNAME"
  150. backup_directory_to_friend /home/$USERNAME/.ssh ssh/$USERNAME
  151. fi
  152. # config files
  153. if [ -d /home/$USERNAME/.config ]; then
  154. echo $"Backing up config files for $USERNAME"
  155. backup_directory_to_friend /home/$USERNAME/.config config/$USERNAME
  156. fi
  157. # mutt settings
  158. if [ -f /home/$USERNAME/.muttrc ]; then
  159. echo $"Backing up Mutt settings for $USERNAME"
  160. if [ ! -d /home/$USERNAME/tempbackup ]; then
  161. mkdir -p /home/$USERNAME/tempbackup
  162. fi
  163. cp /home/$USERNAME/.muttrc /home/$USERNAME/tempbackup
  164. if [ -f /etc/Muttrc ]; then
  165. cp /etc/Muttrc /home/$USERNAME/tempbackup
  166. fi
  167. backup_directory_to_friend /home/$USERNAME/tempbackup mutt/$USERNAME
  168. fi
  169. # procmail settings
  170. if [ -f /home/$USERNAME/.procmailrc ]; then
  171. echo $"Backing up procmail settings for $USERNAME"
  172. if [ ! -d /home/$USERNAME/tempbackup ]; then
  173. mkdir -p /home/$USERNAME/tempbackup
  174. fi
  175. cp /home/$USERNAME/.procmailrc /home/$USERNAME/tempbackup
  176. backup_directory_to_friend /home/$USERNAME/tempbackup procmail/$USERNAME
  177. fi
  178. # spamassassin settings
  179. if [ -d /home/$USERNAME/.spamassassin ]; then
  180. echo $"Backing up spamassassin settings for $USERNAME"
  181. backup_directory_to_friend /home/$USERNAME/.spamassassin spamassassin/$USERNAME
  182. fi
  183. # email
  184. if [ -d /home/$USERNAME/Maildir ]; then
  185. echo $"Creating an email archive"
  186. if [ ! -d /root/backupemail/$USERNAME ]; then
  187. mkdir -p /root/backupemail/$USERNAME
  188. fi
  189. tar -czvf /root/backupemail/$USERNAME/maildir.tar.gz /home/$USERNAME/Maildir
  190. echo $"Backing up emails for $USERNAME"
  191. backup_directory_to_friend /root/backupemail/$USERNAME mail/$USERNAME
  192. fi
  193. fi
  194. done
  195. }
  196. function backup_letsencrypt {
  197. if [ -d /etc/letsencrypt ]; then
  198. echo $"Backing up Lets Encrypt settings"
  199. backup_directory_to_friend /etc/letsencrypt letsencrypt
  200. fi
  201. }
  202. function backup_gnusocial {
  203. if grep -q "GNU Social domain" $COMPLETION_FILE; then
  204. MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
  205. if [ -d /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs ]; then
  206. backup_database_to_friend gnusocial
  207. backup_directory_to_friend /root/tempgnusocialdata gnusocialdata
  208. echo $"Backing up GNU social installation"
  209. backup_directory_to_friend /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs gnusocial
  210. else
  211. echo $"GNU Social domain specified but not found in /var/www/${MICROBLOG_DOMAIN_NAME}"
  212. fi
  213. fi
  214. }
  215. function backup_hubzilla {
  216. if grep -q "Hubzilla domain" $COMPLETION_FILE; then
  217. HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
  218. if [ -d /var/www/${HUBZILLA_DOMAIN_NAME} ]; then
  219. backup_database_to_friend hubzilla
  220. backup_directory_to_friend /root/temphubzilladata hubzilladata
  221. echo "Backing up Hubzilla installation"
  222. backup_directory_to_friend /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs hubzilla
  223. else
  224. echo $"Hubzilla domain specified but not found in /var/www/${HUBZILLA_DOMAIN_NAME}"
  225. exit 2578
  226. fi
  227. fi
  228. }
  229. function backup_owncloud {
  230. if [ -d /etc/owncloud ]; then
  231. backup_database_to_friend owncloud
  232. backup_directory_to_friend /root/tempownclouddata ownclouddata
  233. echo $"Backing up Owncloud data"
  234. backup_directory_to_friend /var/lib/owncloud owncloud
  235. backup_directory_to_friend /etc/owncloud owncloud2
  236. fi
  237. }
  238. function backup_gogs {
  239. if [ -d /home/git/go/src/github.com/gogits ]; then
  240. backup_database_to_friend gogs
  241. backup_directory_to_friend /root/tempgogsdata gogsdata
  242. echo $"Obtaining Gogs settings backup"
  243. backup_directory_to_friend /home/git/go/src/github.com/gogits/gogs/custom gogs
  244. echo $"Obtaining Gogs repos backup"
  245. mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/bob
  246. backup_directory_to_friend /home/git/gogs-repositories gogsrepos
  247. echo $"Obtaining Gogs authorized_keys backup"
  248. backup_directory_to_friend /home/git/.ssh gogsssh
  249. fi
  250. }
  251. function backup_wiki {
  252. if [ -d /etc/dokuwiki ]; then
  253. echo $"Backing up wiki"
  254. backup_directory_to_friend /var/lib/dokuwiki wiki
  255. backup_directory_to_friend /etc/dokuwiki wiki2
  256. fi
  257. }
  258. function backup_blog {
  259. if grep -q "Blog domain" $COMPLETION_FILE; then
  260. FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
  261. if [ -d /var/www/${FULLBLOG_DOMAIN_NAME} ]; then
  262. echo $"Backing up blog"
  263. backup_directory_to_friend /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs blog
  264. else
  265. echo $"Blog domain specified but not found in /var/www/${FULLBLOG_DOMAIN_NAME}"
  266. exit 2578
  267. fi
  268. fi
  269. }
  270. function backup_certs {
  271. if [ -d /etc/ssl ]; then
  272. echo $"Backing up certificates"
  273. backup_directory_to_friend /etc/ssl ssl
  274. fi
  275. }
  276. function backup_mailing_list {
  277. if [ -d /var/spool/mlmmj ]; then
  278. echo $"Backing up the public mailing list"
  279. backup_directory_to_friend /var/spool/mlmmj mailinglist
  280. fi
  281. }
  282. function backup_xmpp {
  283. if [ -d /var/lib/prosody ]; then
  284. echo $"Backing up the XMPP settings"
  285. backup_directory_to_friend /var/lib/prosody xmpp
  286. fi
  287. }
  288. function backup_web_server {
  289. if [ -d /etc/nginx ]; then
  290. echo $"Backing up web settings"
  291. backup_directory_to_friend /etc/nginx/sites-available web
  292. fi
  293. }
  294. function backup_admin_readme {
  295. if [ -f /home/$ADMIN_USERNAME/README ]; then
  296. echo $"Backing up README"
  297. if [ ! -d /home/$ADMIN_USERNAME/tempbackup ]; then
  298. mkdir -p /home/$ADMIN_USERNAME/tempbackup
  299. fi
  300. cp -f /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/tempbackup
  301. backup_directory_to_friend /home/$ADMIN_USERNAME/tempbackup readme
  302. fi
  303. }
  304. function backup_ipfs {
  305. if [ -d /home/$ADMIN_USERNAME/.ipfs ]; then
  306. echo $"Backing up IPFS"
  307. backup_directory_to_friend /home/$ADMIN_USERNAME/.ipfs ipfs
  308. fi
  309. }
  310. function backup_dlna {
  311. if [ -d /var/cache/minidlna ]; then
  312. echo $"Backing up DLNA cache"
  313. backup_directory_to_friend /var/cache/minidlna dlna
  314. fi
  315. }
  316. function backup_voip {
  317. if [ -f /etc/mumble-server.ini ]; then
  318. echo $"Backing up VoIP settings"
  319. if [ ! -d /root/tempvoipbackup ]; then
  320. mkdir -p /root/tempvoipbackup
  321. fi
  322. cp -f /etc/mumble-server.ini /root/tempvoipbackup
  323. cp -f /var/lib/mumble-server/mumble-server.sqlite /root/tempvoipbackup
  324. cp -f /etc/sipwitch.conf /root/tempvoipbackup
  325. backup_directory_to_friend /root/tempvoipbackup voip
  326. fi
  327. }
  328. function backup_tox {
  329. if [ -d /var/lib/tox-bootstrapd ]; then
  330. echo "Backing up Tox node settings"
  331. if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
  332. rm -rf /var/lib/tox-bootstrapd/Maildir
  333. fi
  334. cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
  335. backup_directory_to_friend /var/lib/tox-bootstrapd tox
  336. fi
  337. }
  338. function backup_mariadb {
  339. if [ ${#DATABASE_PASSWORD} -gt 1 ]; then
  340. if [ ! -d /root/tempmariadb ]; then
  341. mkdir /root/tempmariadb
  342. fi
  343. mysqldump --password=$DATABASE_PASSWORD mysql user > /root/tempmariadb/mysql.sql
  344. if [ ! -s /root/tempmariadb/mysql.sql ]; then
  345. echo $"Unable to backup MariaDB settings"
  346. rm -rf /root/tempmariadb
  347. # Send a warning email
  348. echo $"Unable to export database settings" | mail -s "${PROJECT_NAME} backup to friends" $ADMIN_EMAIL_ADDRESS
  349. exit 653
  350. fi
  351. echo "$DATABASE_PASSWORD" > /root/tempmariadb/db
  352. chmod 400 /root/tempmariadb/db
  353. backup_directory_to_friend /root/tempmariadb mariadb
  354. fi
  355. }
  356. # Returns the filename of a key share
  357. function get_key_share {
  358. no_of_shares=$1
  359. USERNAME="$2"
  360. REMOTE_DOMAIN="$3"
  361. # Get a share index based on the supplied domain name
  362. # This ensures that the same share is always given to the same domain
  363. sharenumstr=$(md5sum <<< "$REMOTE_DOMAIN")
  364. share_index=$(echo $((0x${sharenumstr%% *} % ${no_of_shares})) | tr -d -)
  365. # get the filename
  366. share_files=(/home/$USERNAME/.gnupg_fragments/keyshare.asc.*)
  367. share_filename=${share_files[share_index]}
  368. echo "$share_filename"
  369. }
  370. function disperse_key_shares {
  371. USERNAME=$1
  372. REMOTE_DOMAIN=$2
  373. REMOTE_SSH_PORT=$3
  374. REMOTE_PASSWORD=$4
  375. REMOTE_SERVER=$5
  376. if [ -d /home/$USERNAME/.gnupg_fragments ]; then
  377. if [ $REMOTE_DOMAIN ]; then
  378. cd /home/$USERNAME/.gnupg_fragments
  379. no_of_shares=$(ls -afq keyshare.asc.* | wc -l)
  380. if (( no_of_shares > 1 )); then
  381. share_filename=$(get_key_share $no_of_shares "$USERNAME" "$REMOTE_DOMAIN")
  382. # create a temp directory containing the share
  383. temp_key_share_dir=/home/$USERNAME/tempkey
  384. temp_key_share_fragments=$temp_key_share_dir/.gnupg_fragments_${USERNAME}
  385. mkdir -p $temp_key_share_fragments
  386. cp $share_filename $temp_key_share_fragments/
  387. # copy the fragments directory to the remote server
  388. /usr/bin/sshpass -p "$REMOTE_PASSWORD" \
  389. scp -r -P $REMOTE_SSH_PORT $temp_key_share_fragments $REMOTE_SERVER
  390. if [ ! "$?" = "0" ]; then
  391. # Send a warning email
  392. echo "Key share to $REMOTE_SERVER failed" | \
  393. mail -s "${PROJECT_NAME} social key management" $MY_EMAIL_ADDRESS
  394. else
  395. # Send a confirmation email
  396. echo "Key ${share_filename} shared to $REMOTE_SERVER" | \
  397. mail -s "${PROJECT_NAME} social key management" $MY_EMAIL_ADDRESS
  398. fi
  399. # remove the temp file/directory
  400. shred -zu $temp_key_share_fragments/*
  401. rm -rf $temp_key_share_dir
  402. fi
  403. fi
  404. fi
  405. }
  406. function valid_backup_destination {
  407. destination_dir="$1"
  408. is_valid="yes"
  409. if [[ "$destination_dir" == "hubzilla" || \
  410. "$destination_dir" == "hubzilladata" || \
  411. "$destination_dir" == "gogs" || \
  412. "$destination_dir" == "gogsrepos" || \
  413. "$destination_dir" == "gogsssh" || \
  414. "$destination_dir" == "gnusocial" || \
  415. "$destination_dir" == "gnusocialdata" || \
  416. "$destination_dir" == "mariadb" || \
  417. "$destination_dir" == "config" || \
  418. "$destination_dir" == "letsencrypt" || \
  419. "$destination_dir" == "wiki" || \
  420. "$destination_dir" == "wiki2" || \
  421. "$destination_dir" == "xmpp" || \
  422. "$destination_dir" == "ipfs" || \
  423. "$destination_dir" == "dlna" || \
  424. "$destination_dir" == "tox" || \
  425. "$destination_dir" == "ssl" || \
  426. "$destination_dir" == "blog" || \
  427. "$destination_dir" == "owncloud" || \
  428. "$destination_dir" == "owncloud2" || \
  429. "$destination_dir" == "ownclouddata" || \
  430. "$destination_dir" == "mailinglist" ]]; then
  431. is_valid="no"
  432. fi
  433. echo $is_valid
  434. }
  435. function backup_extra_directories {
  436. if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then
  437. return
  438. fi
  439. echo $"Backing up some additional directories"
  440. while read backup_line
  441. do
  442. backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
  443. if [ -d "$backup_dir" ]; then
  444. destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
  445. if [[ $(valid_backup_destination "$destination_dir") == "yes" ]]; then
  446. backup_directory_to_friend "$backup_dir" "$destination_dir"
  447. else
  448. echo $"WARNING: The backup directory $destination_dir is already used."
  449. echo $"Choose a different destination name for backing up $backup_dir"
  450. fi
  451. else
  452. echo $"WARNING: Directory $backup_dir does not exist"
  453. fi
  454. done <$BACKUP_EXTRA_DIRECTORIES
  455. }
  456. backup_configuration
  457. backup_users
  458. backup_letsencrypt
  459. backup_gnusocial
  460. backup_hubzilla
  461. backup_owncloud
  462. backup_gogs
  463. backup_wiki
  464. backup_blog
  465. backup_certs
  466. backup_mailing_list
  467. backup_xmpp
  468. backup_web_server
  469. backup_admin_readme
  470. backup_ipfs
  471. backup_dlna
  472. backup_voip
  473. backup_tox
  474. backup_mariadb
  475. backup_extra_directories
  476. # For each remote server
  477. while read remote_server
  478. do
  479. # Get the server and its password
  480. # Format is:
  481. # username@domain <port number> /home/username <ssh password>
  482. REMOTE_SERVER=$(echo "${remote_server}" | awk -F ' ' '{print $1}')
  483. if [ $REMOTE_SERVER ]; then
  484. REMOTE_DOMAIN=$(echo "${remote_server}" | awk -F ' ' '{print $1}' | awk -F '@' '{print $2}')
  485. REMOTE_SSH_PORT=$(echo "${remote_server}" | awk -F ' ' '{print $2}')
  486. REMOTE_DIRECTORY=$(echo "${remote_server}" | awk -F ' ' '{print $3}')
  487. REMOTE_PASSWORD=$(echo "${remote_server}" | awk -F ' ' '{print $4}')
  488. NOW=$(date +"%Y-%m-%d %H:%M:%S")
  489. REMOTE_SERVER=$REMOTE_SERVER:$REMOTE_DIRECTORY
  490. echo "$NOW Starting backup to $REMOTE_SERVER" >> /var/log/remotebackups.log
  491. # Social key management
  492. for d in /home/*/ ; do
  493. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  494. if [[ $USERNAME != "git" ]]; then
  495. disperse_key_shares $USERNAME $REMOTE_DOMAIN $REMOTE_SSH_PORT "$REMOTE_PASSWORD" $REMOTE_SERVER
  496. fi
  497. done
  498. rsync -ratlzv --rsh="/usr/bin/sshpass -p \"$REMOTE_PASSWORD\" ssh -p $REMOTE_SSH_PORT -o StrictHostKeyChecking=no" $SERVER_DIRECTORY/backup $REMOTE_SERVER
  499. if [ ! "$?" = "0" ]; then
  500. echo "$NOW Backup to $REMOTE_SERVER failed" >> /var/log/remotebackups.log
  501. # Send a warning email
  502. echo "Backup to $REMOTE_SERVER failed" | mail -s "${PROJECT_NAME} backup to friends" $ADMIN_EMAIL_ADDRESS
  503. else
  504. echo "$NOW Backed up to $REMOTE_SERVER" >> /var/log/remotebackups.log
  505. fi
  506. fi
  507. done < /home/${ADMIN_USERNAME}/backup.list
  508. exit 0