freedombone-backup-remote 20KB

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