diff --git a/Makefile b/Makefile index f94dc123..38b546df 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ install: install -m 755 src/${APP}-meshweb ${DESTDIR}${PREFIX}/bin/meshweb install -m 755 src/${APP}-controlpanel ${DESTDIR}${PREFIX}/bin/control install -m 755 src/${APP}-backup-local ${DESTDIR}${PREFIX}/bin/backup + install -m 755 src/${APP}-backup-local ${DESTDIR}${PREFIX}/bin/backup2friends install -m 755 src/${APP}-restore-local ${DESTDIR}${PREFIX}/bin/restore mkdir -m 755 -p ${DESTDIR}${PREFIX}/share/man/man1 install -m 644 man/*.1.gz ${DESTDIR}${PREFIX}/share/man/man1 @@ -31,6 +32,7 @@ uninstall: rm -f ${PREFIX}/bin/zeronetavahi rm -f ${PREFIX}/bin/mesh rm -f ${PREFIX}/bin/backup + rm -f ${PREFIX}/bin/backup2friends rm -f ${PREFIX}/bin/restore rm -f ${PREFIX}/bin/meshweb rm -rf /etc/freedombone diff --git a/man/freedombone-backup-remote.1.gz b/man/freedombone-backup-remote.1.gz new file mode 100644 index 00000000..6c0a482f Binary files /dev/null and b/man/freedombone-backup-remote.1.gz differ diff --git a/src/freedombone b/src/freedombone index a63e008c..d59a1890 100755 --- a/src/freedombone +++ b/src/freedombone @@ -3123,643 +3123,14 @@ function create_freedns_updater { echo 'create_freedns_updater' >> $COMPLETION_FILE } -function backup_directory_to_friend { - echo 'function backup_directory_to_friend {' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo " MY_NAME=$MY_NAME" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo " BACKUP_CERTIFICATE=$BACKUP_CERTIFICATE" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo " MY_EMAIL_ADDRESS=$MY_EMAIL_ADDRESS" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - if [[ $BACKUP_TYPE == 'obnam' ]]; then - echo ' BACKUP_KEY_EXISTS=$(gpg --list-keys "$MY_NAME (backup key)")' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backup key could not be found"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' exit 43382' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n ' MY_BACKUP_KEY_ID=$(gpg --list-keys "$MY_NAME (backup key)" ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n "| grep 'pub ' | awk -F ' ' '{print " >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n '$2' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n "}' | awk -F '/' '{print " >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n '$2' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "}')" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo ' obnam force-lock -r $SERVER_DIRECTORY/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' obnam backup -r $SERVER_DIRECTORY/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n " obnam forget --keep=${BACKUP_MAX_DAYS}d " >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '-r $SERVER_DIRECTORY/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - else - # For rsyncrypto usage see http://archive09.linux.com/feature/125322 - echo -n ' rsyncrypto -v -r ${1} ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n '$SERVER_DIRECTORY/backup/' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n '${2} ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n '$SERVER_DIRECTORY/backup/' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '${2}.keys $BACKUP_CERTIFICATE' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - fi - echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' shred -zu /root/temp${2}/*' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' rm -rf /root/temp${2}' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' # Send a warning email' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n ' echo "Unable to backup ${2}" | mail -s "Freedombone backup to friends" ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '$MY_EMAIL_ADDRESS' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' exit 853' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' shred -zu /root/temp${2}/*' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' rm -rf /root/temp${2}' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '}' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME -} - -function backup_database_to_friend { - echo 'function backup_database_to_friend {' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo " DATABASE_PASSWORD=$DATABASE_PASSWORD" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo " MY_EMAIL_ADDRESS=$MY_EMAIL_ADDRESS" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/${1} ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/${1}' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/${1}data ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/${1}data' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d /root/temp${1}data ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p /root/temp${1}data' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Obtaining ${1} database backup"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n ' mysqldump --password=$DATABASE_PASSWORD ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '${1} > /root/temp${1}data/${1}.sql' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -s /root/temp${1}data/${1}.sql ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "${1} database could not be saved"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! $DATABASE_PASSWORD ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "No MariaDB password was given"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' shred -zu /root/temp${1}data/*' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' rm -rf /root/temp${1}data' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' # Send a warning email' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n ' echo "Unable to export ${1} database" | mail -s "Freedombone backup to friends" ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '$MY_EMAIL_ADDRESS' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' exit 5738' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '}' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME -} - function backup_to_friends_servers { if grep -Fxq "backup_to_friends_servers" $COMPLETION_FILE; then return fi - if [ ! $FRIENDS_SERVERS_LIST ]; then - return - fi - - apt-get -y install rsyncrypto sshpass obnam - - get_mariadb_password - get_mariadb_gnusocial_admin_password - get_mariadb_hubzilla_admin_password - get_mariadb_owncloud_admin_password - get_mariadb_git_admin_password - - if ! grep -q "backups on friends servers" /home/$MY_USERNAME/README; then - echo '' >> /home/$MY_USERNAME/README - echo '' >> /home/$MY_USERNAME/README - echo 'Backups' >> /home/$MY_USERNAME/README - echo '=======' >> /home/$MY_USERNAME/README - echo 'Key file: /root/backupkey' >> /home/$MY_USERNAME/README - echo "To add friends servers create a file called $FRIENDS_SERVERS_LIST" >> /home/$MY_USERNAME/README - echo 'and add entries like this:' >> /home/$MY_USERNAME/README - echo '' >> /home/$MY_USERNAME/README - echo "username1@domain1:$SSH_PORT//home/username1 ssh_password1" >> /home/$MY_USERNAME/README - echo "username2@domain2:$SSH_PORT//home/username2 ssh_password2" >> /home/$MY_USERNAME/README - echo '...' >> /home/$MY_USERNAME/README - echo '' >> /home/$MY_USERNAME/README - echo 'The system will try to backup to these remote locations once per day.' >> /home/$MY_USERNAME/README - chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README - chmod 600 /home/$MY_USERNAME/README - fi - - echo '#!/bin/bash' > /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo '# Temporary location for data to be backed up to other servers' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'SERVER_DIRECTORY=/root/remotebackup' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo "COMPLETION_FILE=$COMPLETION_FILE" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n 'ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n "awk -F ':' '{print " >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n '$2' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "}')" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'MY_USERNAME=$ADMIN_USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo "if [ ! -f $BACKUP_CERTIFICATE ]; then" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Creating backup key"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo " freedombone-addcert -h backup --dhkey $DH_KEYLENGTH" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo "if [ ! -f $FRIENDS_SERVERS_LIST ]; then" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' exit 1' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo '# MariaDB password' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n 'DATABASE_PASSWORD=$(cat ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "$DATABASE_PASSWORD_FILE)" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - - echo '# local directory where the backup will be made' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'if [ ! -d $SERVER_DIRECTORY ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir $SERVER_DIRECTORY' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'if [ ! -d $SERVER_DIRECTORY/backup ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - backup_directory_to_friend - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - backup_database_to_friend - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo 'if [ -d /etc/letsencrypt ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backing up Lets Encrypt settings"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' backup_directory_to_friend /etc/letsencrypt letsencrypt' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - if grep -Fxq "install_gnu_social" $COMPLETION_FILE; then - BACKUP_INCLUDES_DATABASES="yes" - echo 'backup_database_to_friend gnusocial' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'backup_directory_to_friend /root/tempgnusocialdata gnusocialdata' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'echo "Backing up GNU social installation"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "backup_directory_to_friend /var/www/$MICROBLOG_DOMAIN_NAME/htdocs gnusocial" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - fi - if grep -Fxq "install_hubzilla" $COMPLETION_FILE; then - BACKUP_INCLUDES_DATABASES="yes" - echo 'backup_database_to_friend hubzilla' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'backup_directory_to_friend /root/temphubzilladata hubzilladata' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'echo "Backing up Hubzilla installation"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'backup_directory_to_friend /var/www/$HUBZILLA_DOMAIN_NAME/htdocs hubzilla' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - fi - if grep -Fxq "install_owncloud" $COMPLETION_FILE; then - BACKUP_INCLUDES_DATABASES="yes" - echo 'if [ ! -d $SERVER_DIRECTORY/backup/owncloud2 ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/owncloud2' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'backup_database_to_friend owncloud' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'backup_directory_to_friend /root/tempownclouddata ownclouddata' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'echo "Obtaining Owncloud data backup"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'backup_directory_to_friend /var/lib/owncloud owncloud' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'backup_directory_to_friend /etc/owncloud owncloud2' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - fi - - if grep -Fxq "install_gogs" $COMPLETION_FILE; then - BACKUP_INCLUDES_DATABASES="yes" - echo 'if [ ! -d $SERVER_DIRECTORY/backup/gogsrepos ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/gogsrepos' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'if [ ! -d $SERVER_DIRECTORY/backup/gogsssh ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/gogsssh' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'backup_database_to_friend gogs' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'backup_directory_to_friend /root/tempgogsdata gogsdata' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'echo "Obtaining Gogs settings backup"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'backup_directory_to_friend /home/git/go/src/github.com/gogits/gogs/custom gogs' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'echo "Obtaining Gogs repos backup"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/$MY_USERNAME" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'backup_directory_to_friend /home/git/gogs-repositories gogsrepos' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo 'echo "Obtaining Gogs authorized_keys backup"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'backup_directory_to_friend /home/git/.ssh gogsssh' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - fi - - if grep -Fxq "install_wiki" $COMPLETION_FILE; then - echo 'if [ ! -d $SERVER_DIRECTORY/backup/wiki ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/wiki' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'if [ ! -d $SERVER_DIRECTORY/backup/wiki2 ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/wiki2' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'echo "Obtaining wiki data backup"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'backup_directory_to_friend /var/lib/dokuwiki wiki' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'backup_directory_to_friend /etc/dokuwiki wiki2' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - fi - if grep -Fxq "install_blog" $COMPLETION_FILE; then - echo 'if [ ! -d $SERVER_DIRECTORY/backup/blog ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/blog' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'echo "Obtaining blog backup"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "backup_directory_to_friend /var/www/$FULLBLOG_DOMAIN_NAME/htdocs blog" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - fi - if grep -Fxq "mesh_cjdns" $COMPLETION_FILE; then - echo 'if [ ! -d $SERVER_DIRECTORY/backup/cjdns ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/cjdns' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'echo "Obtaining cjdns backup"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'backup_directory_to_friend /etc/cjdns cjdns' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - fi - - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '# Backup certificates' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "if [ -d /etc/ssl ]; then" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backing up certificates"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/ssl ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/ssl' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' backup_directory_to_friend /etc/ssl ssl' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo '# Backup projects' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'for d in /home/*/ ; do' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ -d /home/$USERNAME/projects ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backing up projects for $USERNAME"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/projects/$USERNAME ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/projects/$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' backup_directory_to_friend /home/$USERNAME/projects projects/$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'done' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo '# Backup personal settings' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'for d in /home/*/ ; do' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ -d /home/$USERNAME/personal ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backing up personal settings for $USERNAME"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/personal/$USERNAME ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/personal/$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' backup_directory_to_friend /home/$USERNAME/personal personal/$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'done' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo '# Backup the public mailing list' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "if [ -d $PUBLIC_MAILING_LIST_DIRECTORY ]; then" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backing up the public mailing list"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/mailinglist ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/mailinglist' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo " backup_directory_to_friend $PUBLIC_MAILING_LIST_DIRECTORY mailinglist" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo '# Backup xmpp settings' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "if [ -d $XMPP_DIRECTORY ]; then" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backing up the XMPP settings"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/xmpp ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/xmpp' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo " backup_directory_to_friend $XMPP_DIRECTORY xmpp" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo '# Backup gpg keys' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'for d in /home/*/ ; do' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ -d /home/$USERNAME/.gnupg ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backing up gpg keys for $USERNAME"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/gnupg/$USERNAME ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/gnupg/$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' backup_directory_to_friend /home/$USERNAME/.gnupg gnupg/$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'done' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo '# Backup ssh keys' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'for d in /home/*/ ; do' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ -d /home/$USERNAME/.ssh ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backing up ssh keys for $USERNAME"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/ssh/$USERNAME ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/ssh/$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' backup_directory_to_friend /home/$USERNAME/.ssh ssh/$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'done' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo '# Backup config files' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'for d in /home/*/ ; do' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ -d /home/$USERNAME/.config ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backing up config files for $USERNAME"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/config/$USERNAME ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/config/$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' backup_directory_to_friend /home/$USERNAME/.config config/$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'done' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo '# Backup web sites' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "if [ -d /etc/nginx ]; then" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backing up web settings"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/web ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/web' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' backup_directory_to_friend /etc/nginx/sites-available web' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo '# Backup README file' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'if [ -f /home/$MY_USERNAME/README ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backing up README"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/readme ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/readme' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d /home/$MY_USERNAME/tempbackup ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p /home/$MY_USERNAME/tempbackup' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' cp -f /home/$MY_USERNAME/README /home/$MY_USERNAME/tempbackup' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' backup_directory_to_friend /home/$MY_USERNAME/tempbackup readme' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo '# Backup IPFS' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'if [ -d /home/$MY_USERNAME/.ipfs ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backing up IPFS"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/ipfs ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/ipfs' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' backup_directory_to_friend /home/$MY_USERNAME/.ipfs ipfs' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo '# Backup Mutt settings' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'for d in /home/*/ ; do' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ -f /home/$USERNAME/.muttrc ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backing up Mutt settings for $USERNAME"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d /home/$USERNAME/tempbackup ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p /home/$USERNAME/tempbackup' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' cp /home/$USERNAME/.muttrc /home/$USERNAME/tempbackup' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ -f /etc/Muttrc ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' cp /etc/Muttrc /home/$USERNAME/tempbackup' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/mutt/$USERNAME ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/mutt/$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' backup_directory_to_friend /home/$USERNAME/tempbackup mutt/$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'done' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo '# Backup procmail settings' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'for d in /home/*/ ; do' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ -f /home/$USERNAME/.procmailrc ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backing up procmail settings for $USERNAME"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d /home/$USERNAME/tempbackup ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p /home/$USERNAME/tempbackup' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' cp /home/$USERNAME/.procmailrc /home/$USERNAME/tempbackup' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/procmail/$USERNAME ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/procmail/$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' backup_directory_to_friend /home/$USERNAME/tempbackup procmail/$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'done' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo '# Backup spamassassin settings' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'for d in /home/*/ ; do' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ -d /home/$USERNAME/.spamassassin ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backing up spamassassin settings for $USERNAME"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/spamassassin/$USERNAME ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/spamassassin/$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' backup_directory_to_friend /home/$USERNAME/.spamassassin spamassassin/$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'done' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo '# Backup email' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'for d in /home/*/ ; do' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ -d /home/$USERNAME/Maildir ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Creating an email archive"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d /root/backupemail/$USERNAME ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p /root/backupemail/$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' tar -czvf /root/backupemail/$USERNAME/maildir.tar.gz /home/$USERNAME/Maildir' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backing up emails for $USERNAME"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/mail/$USERNAME ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/mail/$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' backup_directory_to_friend /root/backupemail/$USERNAME mail/$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'done' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo '# Backup DLNA cache' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "if [ -d /var/cache/minidlna ]; then" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backing up DLNA cache"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/dlna ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/dlna' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' backup_directory_to_friend /var/cache/minidlna dlna' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo '# Backup VoIP settings' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "if [ -f /etc/$VOIP_CONFIG_FILE ]; then" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backing up VoIP settings"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d /home/$MY_USERNAME/tempbackup ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p /home/$MY_USERNAME/tempbackup' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n " cp -f /etc/$VOIP_CONFIG_FILE " >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '/home/$MY_USERNAME/tempbackup' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n " cp -f /var/lib/mumble-server/$VOIP_DATABASE " >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '/home/$MY_USERNAME/tempbackup' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n ' cp -f /etc/sipwitch.conf ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '/home/$MY_USERNAME/tempbackup' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/voip ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/voip' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' backup_directory_to_friend /home/$MY_USERNAME/tempbackup voip' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo '# Backup Tox node settings' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'if [ -d /var/lib/tox-bootstrapd ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Backing up Tox node settings"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! -d $SERVER_DIRECTORY/backup/tox ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/tox' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ -d /var/lib/tox-bootstrapd/Maildir ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' rm -rf /var/lib/tox-bootstrapd/Maildir' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' backup_directory_to_friend /var/lib/tox-bootstrapd tox' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - if [[ $BACKUP_INCLUDES_DATABASES == "yes" ]]; then - echo '# Mysql settings' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'if [ ! -d $SERVER_DIRECTORY/backup/mariadb ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p $SERVER_DIRECTORY/backup/mariadb' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'if [ ! -d /root/tempmariadb ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir /root/tempmariadb' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'mysqldump --password=$DATABASE_PASSWORD mysql user > /root/tempmariadb/mysql.sql' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "if [ ! -s /root/tempmariadb/mysql.sql ]; then" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' echo "Unable to backup mysql settings"' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' rm -rf /root/tempmariadb' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' # Send a warning email' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n ' echo "Unable to export database settings" | mail -s "Freedombone backup to friends" ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "$MY_EMAIL_ADDRESS" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' exit 653' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'echo "$DATABASE_PASSWORD" > /root/tempmariadb/db' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'chmod 400 /root/tempmariadb/db' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'backup_directory_to_friend /root/tempmariadb mariadb' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - fi - - # Now that we have the server directory updated with the encrypted backup - # we just need to rsync it to each friend - - echo '# For each remote server' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'while read remote_server' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'do' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' # Get the server and its password' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' # Format is:' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' # username@domain:/home/username ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n ' REMOTE_SERVER=$(echo "${remote_server}" | ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n "awk -F ' ' '{print " >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n '$1' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "}')" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ $REMOTE_SERVER ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n ' REMOTE_DOMAIN=$(echo "${remote_server}" | ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n "awk -F ':' '{print " >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n '$1' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n "}' | awk -F '@' '{print " >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n '$2' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "}')" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n ' REMOTE_SSH_PORT=$(echo "${remote_server}" | ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n "awk -F ' ' '{print " >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n '$2' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "}')" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n ' REMOTE_PASSWORD=$(echo "${remote_server}" | ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n "awk -F ' ' '{print " >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n '$3' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "}')" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' NOW=$(date +"%Y-%m-%d %H:%M:%S")' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - echo -n ' echo "$NOW Starting backup to $REMOTE_SERVER" >> ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "$REMOTE_BACKUPS_LOG" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - if [[ $ENABLE_SOCIAL_KEY_MANAGEMENT == "yes" ]]; then - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' # Social key management' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' for d in /home/*/ ; do' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ -d /home/$USERNAME/.gnupg_fragments ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ $REMOTE_DOMAIN ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' cd /home/$USERNAME/.gnupg_fragments' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' no_of_shares=$(ls -afq keyshare.asc.* | wc -l)' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if (( no_of_shares > 0 )); then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' # Pick a share index based on the domain name' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' # This ensures that the same share is always given to the same domain' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' sharenumstr=$(md5sum <<< "$REMOTE_DOMAIN")' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' share_index=$(echo $((0x${sharenumstr%% *} % ${no_of_shares})) | tr -d -)' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' # get the share filename' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' share_files=(/home/$USERNAME/.gnupg_fragments/keyshare.asc.*)' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' share_filename=${share_files[share_index]}' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' # create a temp directory containing the share' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' mkdir -p /home/$USERNAME/tempkey/.gnupg_fragments_$USERNAME' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' cp $share_filename /home/$USERNAME/tempkey/.gnupg_fragments_$USERNAME/' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' # copy the fragments directory to the remote server' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n ' /usr/bin/sshpass -p $REMOTE_PASSWORD ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n 'scp -r -P $REMOTE_SSH_PORT ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n '/home/$USERNAME/tempkey/.gnupg_fragments_$USERNAME ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '$REMOTE_SERVER' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' # Send a warning email' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n ' echo "Key share to $REMOTE_SERVER failed" | mail -s "Freedombone social key management" ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "$MY_EMAIL_ADDRESS" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' # remove the temp file/directory' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' shred -zu /home/$USERNAME/tempkey/.gnupg_fragments_$USERNAME/*' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' rm -rf /home/$USERNAME/tempkey' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' # Send a confirmation email' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n ' echo "Key shared to $REMOTE_SERVER" | mail -s "Freedombone social key management" ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "$MY_EMAIL_ADDRESS" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' done' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - fi - - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n ' rsync -ratlzv --rsh="/usr/bin/sshpass -p $REMOTE_PASSWORD ssh -p $REMOTE_SSH_PORT -o StrictHostKeyChecking=no" ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '$SERVER_DIRECTORY/backup $REMOTE_SERVER' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n ' echo "$NOW Backup to $REMOTE_SERVER failed" >> ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "$REMOTE_BACKUPS_LOG" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' # Send a warning email' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n ' echo "Backup to $REMOTE_SERVER failed" | mail -s "Freedombone backup to friends" ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "$MY_EMAIL_ADDRESS" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' else' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo -n ' echo "$NOW Backed up to $REMOTE_SERVER" >> ' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "$REMOTE_BACKUPS_LOG" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo ' fi' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - - # End of the loop - - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo "done < $FRIENDS_SERVERS_LIST" >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo '' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - echo 'exit 0' >> /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - chown root:root /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - chmod 400 /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME - chmod +x /usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME # update crontab echo '#!/bin/bash' > /etc/cron.daily/backuptofriends - echo "/usr/bin/$BACKUP_TO_FRIENDS_SCRIPT_NAME" >> /etc/cron.daily/backuptofriends + echo "/usr/bin/${PROJECT_NAME}-backup-remote" >> /etc/cron.daily/backuptofriends chmod +x /etc/cron.daily/backuptofriends echo 'backup_to_friends_servers' >> $COMPLETION_FILE diff --git a/src/freedombone-backup-remote b/src/freedombone-backup-remote new file mode 100755 index 00000000..24aff05e --- /dev/null +++ b/src/freedombone-backup-remote @@ -0,0 +1,489 @@ +#!/bin/bash +# +# .---. . . +# | | | +# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-. +# | | (.-' (.-' ( | ( )| | | | )( )| | (.-' +# ' ' --' --' -' - -' ' ' -' -' -' ' - --' +# +# Freedom in the Cloud +# +# Backup to remote servers - the web of backups + +# License +# ======= +# +# Copyright (C) 2015 Bob Mottram +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +PROJECT_NAME='freedombone' +COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt + +export TEXTDOMAIN=${PROJECT_NAME}-backup-local +export TEXTDOMAINDIR="/usr/share/locale" + +# Temporary location for data to be backed up to other servers +SERVER_DIRECTORY=/root/remotebackup + +ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}') +ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1) +ADMIN_EMAIL_ADDRESS=${ADMIN_USERNAME}@${HOSTNAME} +if [ ! -f /etc/ssl/private/backup.key ]; then + echo $"Creating backup key" + freedombone-addcert -h backup --dhkey 2048 +fi + +if [ ! -f /home/${ADMIN_USERNAME}/backup.list ]; then + exit 1 +fi + +# MariaDB password +DATABASE_PASSWORD='' +if [ -f /root/dbpass ]; then + DATABASE_PASSWORD=$(cat /root/dbpass) +fi + +# local directory where the backup will be made +if [ ! -d $SERVER_DIRECTORY ]; then + mkdir $SERVER_DIRECTORY +fi + +if [ ! -d $SERVER_DIRECTORY/backup ]; then + mkdir -p $SERVER_DIRECTORY/backup +fi + +function backup_directory_to_friend { + BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)") + if [ ! "$?" = "0" ]; then + echo $"Backup key could not be found" + exit 43382 + fi + ADMIN_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') + obnam force-lock -r $SERVER_DIRECTORY/backup/${2} --encrypt-with $ADMIN_BACKUP_KEY_ID ${1} + obnam backup -r $SERVER_DIRECTORY/backup/${2} --encrypt-with $ADMIN_BACKUP_KEY_ID ${1} + obnam forget --keep=30d -r $SERVER_DIRECTORY/backup/${2} --encrypt-with $ADMIN_BACKUP_KEY_ID + if [ ! "$?" = "0" ]; then + if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then + shred -zu /root/temp${2}/* + rm -rf /root/temp${2} + fi + # Send a warning email + echo "Unable to backup ${2}" | mail -s "${PROJECT_NAME} backup to friends" $ADMIN_EMAIL_ADDRESS + exit 853 + fi + if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then + shred -zu /root/temp${2}/* + rm -rf /root/temp${2} + fi +} + +function backup_database_to_friend { + if [ ${#DATABASE_PASSWORD} -lt 2 ]; then + echo $"No MariaDB password was given" + exit 5783 + fi + if [ ! -d $SERVER_DIRECTORY/backup/${1} ]; then + mkdir -p $SERVER_DIRECTORY/backup/${1} + fi + if [ ! -d $SERVER_DIRECTORY/backup/${1}data ]; then + mkdir -p $SERVER_DIRECTORY/backup/${1}data + fi + if [ ! -d /root/temp${1}data ]; then + mkdir -p /root/temp${1}data + fi + echo "Obtaining ${1} database backup" + mysqldump --password=$DATABASE_PASSWORD ${1} > /root/temp${1}data/${1}.sql + if [ ! -s /root/temp${1}data/${1}.sql ]; then + echo $"${1} database could not be saved" + shred -zu /root/temp${1}data/* + rm -rf /root/temp${1}data + # Send a warning email + echo $"Unable to export ${1} database" | mail -s $"${PROJECT_NAME} backup to friends" $ADMIN_EMAIL_ADDRESS + exit 5738 + fi +} + +# Backup user files +for d in /home/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $3}') + if [[ $USERNAME != "git" ]]; then + + # personal settings + if [ -d /home/$USERNAME/personal ]; then + echo $"Backing up personal settings for $USERNAME" + if [ ! -d $SERVER_DIRECTORY/backup/personal/$USERNAME ]; then + mkdir -p $SERVER_DIRECTORY/backup/personal/$USERNAME + fi + backup_directory_to_friend /home/$USERNAME/personal personal/$USERNAME + fi + + # gpg keys + if [ -d /home/$USERNAME/.gnupg ]; then + echo $"Backing up gpg keys for $USERNAME" + if [ ! -d $SERVER_DIRECTORY/backup/gnupg/$USERNAME ]; then + mkdir -p $SERVER_DIRECTORY/backup/gnupg/$USERNAME + fi + backup_directory_to_friend /home/$USERNAME/.gnupg gnupg/$USERNAME + fi + + # ssh keys + if [ -d /home/$USERNAME/.ssh ]; then + echo $"Backing up ssh keys for $USERNAME" + if [ ! -d $SERVER_DIRECTORY/backup/ssh/$USERNAME ]; then + mkdir -p $SERVER_DIRECTORY/backup/ssh/$USERNAME + fi + backup_directory_to_friend /home/$USERNAME/.ssh ssh/$USERNAME + fi + + # config files + if [ -d /home/$USERNAME/.config ]; then + echo $"Backing up config files for $USERNAME" + if [ ! -d $SERVER_DIRECTORY/backup/config/$USERNAME ]; then + mkdir -p $SERVER_DIRECTORY/backup/config/$USERNAME + fi + backup_directory_to_friend /home/$USERNAME/.config config/$USERNAME + fi + + # mutt settings + if [ -f /home/$USERNAME/.muttrc ]; then + echo $"Backing up Mutt settings for $USERNAME" + if [ ! -d /home/$USERNAME/tempbackup ]; then + mkdir -p /home/$USERNAME/tempbackup + fi + cp /home/$USERNAME/.muttrc /home/$USERNAME/tempbackup + if [ -f /etc/Muttrc ]; then + cp /etc/Muttrc /home/$USERNAME/tempbackup + fi + if [ ! -d $SERVER_DIRECTORY/backup/mutt/$USERNAME ]; then + mkdir -p $SERVER_DIRECTORY/backup/mutt/$USERNAME + fi + backup_directory_to_friend /home/$USERNAME/tempbackup mutt/$USERNAME + fi + + # procmail settings + if [ -f /home/$USERNAME/.procmailrc ]; then + echo $"Backing up procmail settings for $USERNAME" + if [ ! -d /home/$USERNAME/tempbackup ]; then + mkdir -p /home/$USERNAME/tempbackup + fi + cp /home/$USERNAME/.procmailrc /home/$USERNAME/tempbackup + if [ ! -d $SERVER_DIRECTORY/backup/procmail/$USERNAME ]; then + mkdir -p $SERVER_DIRECTORY/backup/procmail/$USERNAME + fi + backup_directory_to_friend /home/$USERNAME/tempbackup procmail/$USERNAME + fi + + # spamassassin settings + if [ -d /home/$USERNAME/.spamassassin ]; then + echo $"Backing up spamassassin settings for $USERNAME" + if [ ! -d $SERVER_DIRECTORY/backup/spamassassin/$USERNAME ]; then + mkdir -p $SERVER_DIRECTORY/backup/spamassassin/$USERNAME + fi + backup_directory_to_friend /home/$USERNAME/.spamassassin spamassassin/$USERNAME + fi + + # email + if [ -d /home/$USERNAME/Maildir ]; then + echo $"Creating an email archive" + if [ ! -d /root/backupemail/$USERNAME ]; then + mkdir -p /root/backupemail/$USERNAME + fi + tar -czvf /root/backupemail/$USERNAME/maildir.tar.gz /home/$USERNAME/Maildir + echo $"Backing up emails for $USERNAME" + if [ ! -d $SERVER_DIRECTORY/backup/mail/$USERNAME ]; then + mkdir -p $SERVER_DIRECTORY/backup/mail/$USERNAME + fi + backup_directory_to_friend /root/backupemail/$USERNAME mail/$USERNAME + fi + fi +done + +# Backup Let's Encrypt +if [ -d /etc/letsencrypt ]; then + echo $"Backing up Lets Encrypt settings" + backup_directory_to_friend /etc/letsencrypt letsencrypt +fi + +# Backup gnusocial +if grep -q "GNU Social domain" $COMPLETION_FILE; then + MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}') + if [ -d /var/www/${MICROBLOG_DOMAIN_NAME} ]; then + backup_database_to_friend gnusocial + backup_directory_to_friend /root/tempgnusocialdata gnusocialdata + echo $"Backing up GNU social installation" + backup_directory_to_friend /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs gnusocial + else + echo $"GNU Social domain specified but not found in /var/www/${MICROBLOG_DOMAIN_NAME}" + exit 6327 + fi +fi + +# backup hubzilla +if grep -q "Hubzilla domain" $COMPLETION_FILE; then + HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}') + if [ -d /var/www/${HUBZILLA_DOMAIN_NAME} ]; then + backup_database_to_friend hubzilla + backup_directory_to_friend /root/temphubzilladata hubzilladata + echo "Backing up Hubzilla installation" + backup_directory_to_friend /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs hubzilla + else + echo $"Hubzilla domain specified but not found in /var/www/${HUBZILLA_DOMAIN_NAME}" + exit 2578 + fi +fi + +# backup owncloud +if [ -d /etc/owncloud ]; then + if [ ! -d $SERVER_DIRECTORY/backup/owncloud2 ]; then + mkdir -p $SERVER_DIRECTORY/backup/owncloud2 + fi + backup_database_to_friend owncloud + backup_directory_to_friend /root/tempownclouddata ownclouddata + echo $"Backing up Owncloud data" + backup_directory_to_friend /var/lib/owncloud owncloud + backup_directory_to_friend /etc/owncloud owncloud2 +fi + +# backup gogs +if [ -d /home/git/go/src/github.com/gogits ]; then + if [ ! -d $SERVER_DIRECTORY/backup/gogsrepos ]; then + mkdir -p $SERVER_DIRECTORY/backup/gogsrepos + fi + if [ ! -d $SERVER_DIRECTORY/backup/gogsssh ]; then + mkdir -p $SERVER_DIRECTORY/backup/gogsssh + fi + backup_database_to_friend gogs + backup_directory_to_friend /root/tempgogsdata gogsdata + echo $"Obtaining Gogs settings backup" + backup_directory_to_friend /home/git/go/src/github.com/gogits/gogs/custom gogs + echo $"Obtaining Gogs repos backup" + mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/bob + backup_directory_to_friend /home/git/gogs-repositories gogsrepos + echo $"Obtaining Gogs authorized_keys backup" + backup_directory_to_friend /home/git/.ssh gogsssh +fi + +if [ -d /etc/dokuwiki ]; then + if [ ! -d $SERVER_DIRECTORY/backup/wiki ]; then + mkdir -p $SERVER_DIRECTORY/backup/wiki + fi + if [ ! -d $SERVER_DIRECTORY/backup/wiki2 ]; then + mkdir -p $SERVER_DIRECTORY/backup/wiki2 + fi + echo $"Backing up wiki" + backup_directory_to_friend /var/lib/dokuwiki wiki + backup_directory_to_friend /etc/dokuwiki wiki2 +fi + +# Backup blog +if grep -q "Blog domain" $COMPLETION_FILE; then + FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}') + if [ -d /var/www/${FULLBLOG_DOMAIN_NAME} ]; then + if [ ! -d $SERVER_DIRECTORY/backup/blog ]; then + mkdir -p $SERVER_DIRECTORY/backup/blog + fi + echo $"Backing up blog" + backup_directory_to_friend /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs blog + else + echo $"Blog domain specified but not found in /var/www/${FULLBLOG_DOMAIN_NAME}" + exit 2578 + fi +fi + +# Backup certificates +if [ -d /etc/ssl ]; then + echo $"Backing up certificates" + if [ ! -d $SERVER_DIRECTORY/backup/ssl ]; then + mkdir -p $SERVER_DIRECTORY/backup/ssl + fi + backup_directory_to_friend /etc/ssl ssl +fi + +# Backup the public mailing list +if [ -d /var/spool/mlmmj ]; then + echo $"Backing up the public mailing list" + if [ ! -d $SERVER_DIRECTORY/backup/mailinglist ]; then + mkdir -p $SERVER_DIRECTORY/backup/mailinglist + fi + backup_directory_to_friend /var/spool/mlmmj mailinglist +fi + +# Backup xmpp settings +if [ -d /var/lib/prosody ]; then + echo $"Backing up the XMPP settings" + if [ ! -d $SERVER_DIRECTORY/backup/xmpp ]; then + mkdir -p $SERVER_DIRECTORY/backup/xmpp + fi + backup_directory_to_friend /var/lib/prosody xmpp +fi + +# Backup web sites +if [ -d /etc/nginx ]; then + echo $"Backing up web settings" + if [ ! -d $SERVER_DIRECTORY/backup/web ]; then + mkdir -p $SERVER_DIRECTORY/backup/web + fi + backup_directory_to_friend /etc/nginx/sites-available web +fi + +# Backup admin user README file +if [ -f /home/$ADMIN_USERNAME/README ]; then + echo $"Backing up README" + if [ ! -d $SERVER_DIRECTORY/backup/readme ]; then + mkdir -p $SERVER_DIRECTORY/backup/readme + fi + if [ ! -d /home/$ADMIN_USERNAME/tempbackup ]; then + mkdir -p /home/$ADMIN_USERNAME/tempbackup + fi + cp -f /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/tempbackup + backup_directory_to_friend /home/$ADMIN_USERNAME/tempbackup readme +fi + +# Backup IPFS +if [ -d /home/$ADMIN_USERNAME/.ipfs ]; then + echo $"Backing up IPFS" + if [ ! -d $SERVER_DIRECTORY/backup/ipfs ]; then + mkdir -p $SERVER_DIRECTORY/backup/ipfs + fi + backup_directory_to_friend /home/$ADMIN_USERNAME/.ipfs ipfs +fi + +# Backup DLNA cache +if [ -d /var/cache/minidlna ]; then + echo $"Backing up DLNA cache" + if [ ! -d $SERVER_DIRECTORY/backup/dlna ]; then + mkdir -p $SERVER_DIRECTORY/backup/dlna + fi + backup_directory_to_friend /var/cache/minidlna dlna +fi + +# Backup VoIP settings +if [ -f /etc/mumble-server.ini ]; then + echo $"Backing up VoIP settings" + if [ ! -d /root/tempvoipbackup ]; then + mkdir -p /root/tempvoipbackup + fi + cp -f /etc/mumble-server.ini /root/tempvoipbackup + cp -f /var/lib/mumble-server/mumble-server.sqlite /root/tempvoipbackup + cp -f /etc/sipwitch.conf /root/tempvoipbackup + if [ ! -d $SERVER_DIRECTORY/backup/voip ]; then + mkdir -p $SERVER_DIRECTORY/backup/voip + fi + backup_directory_to_friend /root/tempvoipbackup voip +fi + +# Backup Tox node settings +if [ -d /var/lib/tox-bootstrapd ]; then + echo "Backing up Tox node settings" + if [ ! -d $SERVER_DIRECTORY/backup/tox ]; then + mkdir -p $SERVER_DIRECTORY/backup/tox + fi + if [ -d /var/lib/tox-bootstrapd/Maildir ]; then + rm -rf /var/lib/tox-bootstrapd/Maildir + fi + cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd + backup_directory_to_friend /var/lib/tox-bootstrapd tox +fi + +# MariaDB settings +if [ ${#DATABASE_PASSWORD} -gt 1 ]; then + if [ ! -d $SERVER_DIRECTORY/backup/mariadb ]; then + mkdir -p $SERVER_DIRECTORY/backup/mariadb + fi + if [ ! -d /root/tempmariadb ]; then + mkdir /root/tempmariadb + fi + mysqldump --password=$DATABASE_PASSWORD mysql user > /root/tempmariadb/mysql.sql + if [ ! -s /root/tempmariadb/mysql.sql ]; then + echo $"Unable to backup MariaDB settings" + rm -rf /root/tempmariadb + # Send a warning email + echo $"Unable to export database settings" | mail -s "${PROJECT_NAME} backup to friends" $ADMIN_EMAIL_ADDRESS + exit 653 + fi + echo "$DATABASE_PASSWORD" > /root/tempmariadb/db + chmod 400 /root/tempmariadb/db + backup_directory_to_friend /root/tempmariadb mariadb +fi + +# For each remote server +while read remote_server +do + # Get the server and its password + # Format is: + # username@domain:/home/username + REMOTE_SERVER=$(echo "${remote_server}" | awk -F ' ' '{print $1}') + if [ $REMOTE_SERVER ]; then + REMOTE_DOMAIN=$(echo "${remote_server}" | awk -F ':' '{print $1}' | awk -F '@' '{print $2}') + REMOTE_SSH_PORT=$(echo "${remote_server}" | awk -F ' ' '{print $2}') + REMOTE_PASSWORD=$(echo "${remote_server}" | awk -F ' ' '{print $3}') + NOW=$(date +"%Y-%m-%d %H:%M:%S") + + echo "$NOW Starting backup to $REMOTE_SERVER" >> /var/log/remotebackups.log + + # Social key management + for d in /home/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $3}') + if [[ $USERNAME != "git" ]]; then + if [ -d /home/$USERNAME/.gnupg_fragments ]; then + if [ $REMOTE_DOMAIN ]; then + cd /home/$USERNAME/.gnupg_fragments + no_of_shares=$(ls -afq keyshare.asc.* | wc -l) + if (( no_of_shares > 0 )); then + # Pick a share index based on the domain name + # This ensures that the same share is always given to the same domain + sharenumstr=$(md5sum <<< "$REMOTE_DOMAIN") + share_index=$(echo $((0x${sharenumstr%% *} % ${no_of_shares})) | tr -d -) + + # get the share filename + share_files=(/home/$USERNAME/.gnupg_fragments/keyshare.asc.*) + share_filename=${share_files[share_index]} + + # create a temp directory containing the share + mkdir -p /home/$USERNAME/tempkey/.gnupg_fragments_$USERNAME + cp $share_filename /home/$USERNAME/tempkey/.gnupg_fragments_$USERNAME/ + + # copy the fragments directory to the remote server + /usr/bin/sshpass -p $REMOTE_PASSWORD scp -r -P $REMOTE_SSH_PORT /home/$USERNAME/tempkey/.gnupg_fragments_$USERNAME $REMOTE_SERVER + if [ ! "$?" = "0" ]; then + # Send a warning email + echo "Key share to $REMOTE_SERVER failed" | mail -s "${PROJECT_NAME} social key management" $MY_EMAIL_ADDRESS + fi + + # remove the temp file/directory + shred -zu /home/$USERNAME/tempkey/.gnupg_fragments_$USERNAME/* + rm -rf /home/$USERNAME/tempkey + + # Send a confirmation email + echo "Key shared to $REMOTE_SERVER" | mail -s "${PROJECT_NAME} social key management" $MY_EMAIL_ADDRESS + fi + fi + fi + fi + done + + rsync -ratlzv --rsh="/usr/bin/sshpass -p $REMOTE_PASSWORD ssh -p $REMOTE_SSH_PORT -o StrictHostKeyChecking=no" $SERVER_DIRECTORY/backup $REMOTE_SERVER + if [ ! "$?" = "0" ]; then + echo "$NOW Backup to $REMOTE_SERVER failed" >> /var/log/remotebackups.log + # Send a warning email + echo "Backup to $REMOTE_SERVER failed" | mail -s "${PROJECT_NAME} backup to friends" $ADMIN_EMAIL_ADDRESS + else + echo "$NOW Backed up to $REMOTE_SERVER" >> /var/log/remotebackups.log + fi + fi + +done < /home/${ADMIN_USERNAME}/backup.list + +exit 0