freedombone-backup-remote 17KB

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