This commit is contained in:
Bob Mottram 2016-07-10 11:04:40 +01:00
parent 56fff9a6cd
commit f11a4f2080
3 changed files with 804 additions and 765 deletions

View File

@ -285,48 +285,51 @@ function prepare_directories {
function backup_configuration { function backup_configuration {
echo $"Backing up ${PROJECT_NAME} configuration files" echo $"Backing up ${PROJECT_NAME} configuration files"
if [ ! -d /root/tempbackupconfig ]; then temp_backup_dir=/root/tempbackupconfig
mkdir -p /root/tempbackupconfig if [ ! -d $temp_backup_dir ]; then
mkdir -p $temp_backup_dir
fi fi
cp -f $CONFIG_FILE /root/tempbackupconfig cp -f $CONFIG_FILE $temp_backup_dir
cp -f $COMPLETION_FILE /root/tempbackupconfig cp -f $COMPLETION_FILE $temp_backup_dir
if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then
cp -f $BACKUP_EXTRA_DIRECTORIES /root/tempbackupconfig cp -f $BACKUP_EXTRA_DIRECTORIES $temp_backup_dir
fi fi
# nginx password hashes # nginx password hashes
if [ -f /etc/nginx/.htpasswd ]; then if [ -f /etc/nginx/.htpasswd ]; then
cp -f /etc/nginx/.htpasswd /root/tempbackupconfig/htpasswd cp -f /etc/nginx/.htpasswd $temp_backup_dir/htpasswd
fi fi
backup_directory_to_usb /root/tempbackupconfig config backup_directory_to_usb $temp_backup_dir config
} }
function backup_admin_readme { function backup_admin_readme {
if [ -f /home/$ADMIN_USERNAME/README ]; then if [ -f /home/$ADMIN_USERNAME/README ]; then
echo $"Backing up README" echo $"Backing up README"
if [ ! -d /home/$ADMIN_USERNAME/tempbackup ]; then temp_backup_dir=/home/$ADMIN_USERNAME/tempbackup
mkdir -p /home/$ADMIN_USERNAME/tempbackup if [ ! -d $temp_backup_dir ]; then
mkdir -p $temp_backup_dir
fi fi
cp -f /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/tempbackup cp -f /home/$ADMIN_USERNAME/README $temp_backup_dir
backup_directory_to_usb /home/$ADMIN_USERNAME/tempbackup readme backup_directory_to_usb $temp_backup_dir readme
fi fi
} }
function backup_mariadb { function backup_mariadb {
if [ ${#DATABASE_PASSWORD} -gt 1 ]; then if [ ${#DATABASE_PASSWORD} -gt 1 ]; then
if [ ! -d /root/tempmariadb ]; then temp_backup_dir=/root/tempmariadb
mkdir /root/tempmariadb if [ ! -d $temp_backup_dir ]; then
mkdir $temp_backup_dir
fi fi
mysqldump --lock-tables --password="$DATABASE_PASSWORD" mysql user > /root/tempmariadb/mysql.sql mysqldump --lock-tables --password="$DATABASE_PASSWORD" mysql user > $temp_backup_dir/mysql.sql
if [ ! -s /root/tempmariadb/mysql.sql ]; then if [ ! -s $temp_backup_dir/mysql.sql ]; then
echo $"Unable to backup mysql settings" echo $"Unable to backup mysql settings"
rm -rf /root/tempmariadb rm -rf $temp_backup_dir
umount $USB_MOUNT umount $USB_MOUNT
rm -rf $USB_MOUNT rm -rf $USB_MOUNT
exit 8 exit 8
fi fi
echo "$DATABASE_PASSWORD" > /root/tempmariadb/db echo "$DATABASE_PASSWORD" > $temp_backup_dir/db
chmod 400 /root/tempmariadb/db chmod 400 $temp_backup_dir/db
backup_directory_to_usb /root/tempmariadb mariadb backup_directory_to_usb $temp_backup_dir mariadb
fi fi
} }

File diff suppressed because it is too large Load Diff

View File

@ -179,12 +179,13 @@ function restore_configuration {
fi fi
if [ -d $SERVER_DIRECTORY/backup/config ]; then if [ -d $SERVER_DIRECTORY/backup/config ]; then
echo $"Restoring configuration files" echo $"Restoring configuration files"
restore_directory_from_friend /root/tempconfig config temp_restore_dir=/root/tempconfig
restore_directory_from_friend $temp_restore_dir config
cp -f /root/tempconfig/root/${PROJECT_NAME}.cfg $CONFIG_FILE cp -f $temp_restore_dir/root/${PROJECT_NAME}.cfg $CONFIG_FILE
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
unmount_drive unmount_drive
rm -rf /root/tempconfig rm -rf $temp_restore_dir
exit 5372 exit 5372
fi fi
if [ -f $CONFIG_FILE ]; then if [ -f $CONFIG_FILE ]; then
@ -192,28 +193,28 @@ function restore_configuration {
freedombone -c $CONFIG_FILE freedombone -c $CONFIG_FILE
fi fi
cp -f /root/tempconfig/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE cp -f $temp_restore_dir/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
unmount_drive unmount_drive
rm -rf /root/tempconfig rm -rf $temp_restore_dir
exit 7252 exit 7252
fi fi
if [ -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ]; then if [ -f ${temp_restore_dir}${BACKUP_EXTRA_DIRECTORIES} ]; then
cp -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES} cp -f ${temp_restore_dir}${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES}
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
unmount_drive unmount_drive
rm -rf /root/tempconfig rm -rf $temp_restore_dir
exit 62121 exit 62121
fi fi
fi fi
# restore nginx password hashes # restore nginx password hashes
if [ -f /root/tempconfig/root/htpasswd ]; then if [ -f $temp_restore_dir/root/htpasswd ]; then
cp -f /root/tempconfig/root/htpasswd /etc/nginx/.htpasswd cp -f $temp_restore_dir/root/htpasswd /etc/nginx/.htpasswd
fi fi
rm -rf /root/tempconfig rm -rf $temp_restore_dir
fi fi
} }
@ -225,19 +226,20 @@ function restore_mariadb {
fi fi
if [ -d $SERVER_DIRECTORY/backup/mariadb ]; then if [ -d $SERVER_DIRECTORY/backup/mariadb ]; then
echo $"Restoring MariaDB settings" echo $"Restoring MariaDB settings"
restore_directory_from_friend /root/tempmariadb mariadb temp_restore_dir=/root/tempmariadb
restore_directory_from_friend $temp_restore_dir mariadb
echo $"Get the MariaDB password from the backup" echo $"Get the MariaDB password from the backup"
if [ ! -f /root/tempmariadb/root/tempmariadb/db ]; then if [ ! -f ${temp_restore_dir}${temp_restore_dir}/db ]; then
echo $"MariaDB password file not found" echo $"MariaDB password file not found"
exit 495 exit 495
fi fi
BACKUP_MARIADB_PASSWORD=$(cat /root/tempmariadb/root/tempmariadb/db) BACKUP_MARIADB_PASSWORD=$(cat ${temp_restore_dir}${temp_restore_dir}/db)
if [[ "$BACKUP_MARIADB_PASSWORD" != "$DATABASE_PASSWORD" ]]; then if [[ "$BACKUP_MARIADB_PASSWORD" != "$DATABASE_PASSWORD" ]]; then
echo $"Restore the MariaDB user table" echo $"Restore the MariaDB user table"
mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" mysql -o < /root/tempmariadb/root/tempmariadb/mysql.sql) mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql)
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
echo $"Try again using the password obtained from backup" echo $"Try again using the password obtained from backup"
mysqlsuccess=$(mysql -u root --password="$BACKUP_MARIADB_PASSWORD" mysql -o < /root/tempmariadb/root/tempmariadb/mysql.sql) mysqlsuccess=$(mysql -u root --password="$BACKUP_MARIADB_PASSWORD" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql)
fi fi
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
echo "$mysqlsuccess" echo "$mysqlsuccess"
@ -248,8 +250,8 @@ function restore_mariadb {
echo $"Change the MariaDB password to the backup version" echo $"Change the MariaDB password to the backup version"
DATABASE_PASSWORD=$BACKUP_MARIADB_PASSWORD DATABASE_PASSWORD=$BACKUP_MARIADB_PASSWORD
fi fi
shred -zu /root/tempmariadb/root/tempmariadb/db shred -zu ${temp_restore_dir}${temp_restore_dir}/db
rm -rf /root/tempmariadb rm -rf ${temp_restore_dir}
# Change database password file # Change database password file
echo "$DATABASE_PASSWORD" > /root/dbpass echo "$DATABASE_PASSWORD" > /root/dbpass
@ -295,18 +297,19 @@ function restore_mutt_settings {
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
fi fi
echo $"Restoring Mutt settings for $USERNAME" echo $"Restoring Mutt settings for $USERNAME"
restore_directory_from_friend /root/tempmutt mutt/$USERNAME temp_restore_dir=/root/tempmutt
if [ -f /root/tempmutt/home/$USERNAME/tempbackup/.muttrc ]; then restore_directory_from_friend ${temp_restore_dir} mutt/$USERNAME
cp -f /root/tempmutt/home/$USERNAME/tempbackup/.muttrc /home/$USERNAME/.muttrc if [ -f ${temp_restore_dir}/home/$USERNAME/tempbackup/.muttrc ]; then
cp -f ${temp_restore_dir}/home/$USERNAME/tempbackup/.muttrc /home/$USERNAME/.muttrc
fi fi
if [ -f /root/tempmutt/home/$USERNAME/tempbackup/Muttrc ]; then if [ -f ${temp_restore_dir}/home/$USERNAME/tempbackup/Muttrc ]; then
cp -f /root/tempmutt/home/$USERNAME/tempbackup/Muttrc /etc/Muttrc cp -f ${temp_restore_dir}/home/$USERNAME/tempbackup/Muttrc /etc/Muttrc
fi fi
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
rm -rf /root/tempmutt rm -rf ${temp_restore_dir}
exit 276 exit 276
fi fi
rm -rf /root/tempmutt rm -rf ${temp_restore_dir}
fi fi
fi fi
done done
@ -326,13 +329,14 @@ function restore_gpg {
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
fi fi
echo $"Restoring gnupg settings for $USERNAME" echo $"Restoring gnupg settings for $USERNAME"
restore_directory_from_friend /root/tempgnupg gnupg/$USERNAME temp_restore_dir=/root/tempgnupg
cp -r /root/tempgnupg/home/$USERNAME/.gnupg /home/$USERNAME/ restore_directory_from_friend ${temp_restore_dir} gnupg/$USERNAME
cp -r ${temp_restore_dir}/home/$USERNAME/.gnupg /home/$USERNAME/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
rm -rf /root/tempgnupg rm -rf ${temp_restore_dir}
exit 276 exit 276
fi fi
rm -rf /root/tempgnupg rm -rf ${temp_restore_dir}
if [[ "$USERNAME" == "$ADMIN_USERNAME" ]]; then if [[ "$USERNAME" == "$ADMIN_USERNAME" ]]; then
cp -r /home/$USERNAME/.gnupg /root cp -r /home/$USERNAME/.gnupg /root
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
@ -358,13 +362,14 @@ function restore_procmail {
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
fi fi
echo $"Restoring procmail settings for $USERNAME" echo $"Restoring procmail settings for $USERNAME"
restore_directory_from_friend /root/tempprocmail procmail/$USERNAME temp_restore_dir=/root/tempprocmail
cp -f /root/tempprocmail/home/$USERNAME/tempbackup/.procmailrc /home/$USERNAME/ restore_directory_from_friend ${temp_restore_dir} procmail/$USERNAME
cp -f ${temp_restore_dir}/home/$USERNAME/tempbackup/.procmailrc /home/$USERNAME/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
rm -rf /root/tempprocmail rm -rf ${temp_restore_dir}
exit 276 exit 276
fi fi
rm -rf /root/tempprocmail rm -rf ${temp_restore_dir}
fi fi
fi fi
done done
@ -384,13 +389,14 @@ function restore_spamassassin {
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
fi fi
echo $"Restoring spamassassin settings for $USERNAME" echo $"Restoring spamassassin settings for $USERNAME"
restore_directory_from_friend /root/tempspamassassin spamassassin/$USERNAME temp_restore_dir=/root/tempspamassassin
cp -rf /root/tempspamassassin/home/$USERNAME/.spamassassin /home/$USERNAME/ restore_directory_from_friend $temp_restore_dir spamassassin/$USERNAME
cp -rf $temp_restore_dir/home/$USERNAME/.spamassassin /home/$USERNAME/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
rm -rf /root/tempspamassassin rm -rf $temp_restore_dir
exit 276 exit 276
fi fi
rm -rf /root/tempspamassassin rm -rf $temp_restore_dir
fi fi
fi fi
done done
@ -404,13 +410,14 @@ function restore_admin_readme {
fi fi
if [ -d $SERVER_DIRECTORY/backup/readme ]; then if [ -d $SERVER_DIRECTORY/backup/readme ]; then
echo $"Restoring README" echo $"Restoring README"
restore_directory_from_friend /root/tempreadme readme temp_restore_dir=/root/tempreadme
cp -f /root/tempreadme/home/$ADMIN_USERNAME/tempbackup/README /home/$ADMIN_USERNAME/ restore_directory_from_friend $temp_restore_dir readme
cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/README /home/$ADMIN_USERNAME/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
rm -rf /root/tempreadme rm -rf $temp_restore_dir
exit 276 exit 276
fi fi
rm -rf /root/tempreadme rm -rf $temp_restore_dir
fi fi
} }
@ -422,13 +429,14 @@ function restore_ipfs {
fi fi
if [ -d $SERVER_DIRECTORY/backup/ipfs ]; then if [ -d $SERVER_DIRECTORY/backup/ipfs ]; then
echo $"Restoring IPFS" echo $"Restoring IPFS"
restore_directory_from_friend /root/tempipfs ipfs temp_restore_dir=/root/tempipfs
cp -rf /root/tempipfs/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs restore_directory_from_friend $temp_restore_dir ipfs
cp -rf $temp_restore_dir/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
rm -rf /root/tempipfs rm -rf $temp_restore_dir
exit 276 exit 276
fi fi
rm -rf /root/tempipfs rm -rf $temp_restore_dir
fi fi
} }
@ -446,13 +454,14 @@ function restore_ssh_keys {
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
fi fi
echo $"Restoring ssh keys for $USERNAME" echo $"Restoring ssh keys for $USERNAME"
restore_directory_from_friend /root/tempssh ssh/$USERNAME temp_restore_dir=/root/tempssh
cp -r /root/tempssh/home/$USERNAME/.ssh /home/$USERNAME/ restore_directory_from_friend $temp_restore_dir ssh/$USERNAME
cp -r $temp_restore_dir/home/$USERNAME/.ssh /home/$USERNAME/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
rm -rf /root/tempssh rm -rf $temp_restore_dir
exit 664 exit 664
fi fi
rm -rf /root/tempssh rm -rf $temp_restore_dir
fi fi
fi fi
done done
@ -472,13 +481,14 @@ function restore_user_config {
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
fi fi
echo $"Restoring config files for $USERNAME" echo $"Restoring config files for $USERNAME"
restore_directory_from_friend /root/tempconfig config/$USERNAME temp_restore_dir=/root/tempconfig
cp -r /root/tempconfig/home/$USERNAME/.config /home/$USERNAME/ restore_directory_from_friend $temp_restore_dir config/$USERNAME
cp -r $temp_restore_dir/home/$USERNAME/.config /home/$USERNAME/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
rm -rf /root/tempconfig rm -rf $temp_restore_dir
exit 664 exit 664
fi fi
rm -rf /root/tempconfig rm -rf $temp_restore_dir
fi fi
fi fi
done done
@ -510,13 +520,14 @@ function restore_user_monkeysphere {
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
fi fi
echo $"Restoring monkeysphere ids for $USERNAME" echo $"Restoring monkeysphere ids for $USERNAME"
restore_directory_from_friend /root/tempmonkeysphere monkeysphere/$USERNAME temp_restore_dir=/root/tempmonkeysphere
cp -r /root/tempmonkeysphere/home/$USERNAME/.monkeysphere /home/$USERNAME/ restore_directory_from_friend $temp_restore_dir monkeysphere/$USERNAME
cp -r $temp_restore_dir/home/$USERNAME/.monkeysphere /home/$USERNAME/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
rm -rf /root/tempmonkeysphere rm -rf $temp_restore_dir
exit 664 exit 664
fi fi
rm -rf /root/tempmonkeysphere rm -rf $temp_restore_dir
fi fi
fi fi
@ -546,13 +557,14 @@ function restore_user_fin {
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
fi fi
echo $"Restoring fin files for $USERNAME" echo $"Restoring fin files for $USERNAME"
restore_directory_from_friend /root/tempfin fin/$USERNAME temp_restore_dir=/root/tempfin
cp -r /root/tempfin/home/$USERNAME/.fin /home/$USERNAME/ restore_directory_from_friend $temp_restore_dir fin/$USERNAME
cp -r $temp_restore_dir/home/$USERNAME/.fin /home/$USERNAME/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
rm -rf /root/tempfin rm -rf $temp_restore_dir
exit 664 exit 664
fi fi
rm -rf /root/tempfin rm -rf $temp_restore_dir
fi fi
fi fi
done done
@ -572,13 +584,14 @@ function restore_user_local {
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
fi fi
echo $"Restoring local files for $USERNAME" echo $"Restoring local files for $USERNAME"
restore_directory_from_friend /root/templocal local/$USERNAME temp_restore_dir=/root/templocal
cp -r /root/templocal/home/$USERNAME/.local /home/$USERNAME/ restore_directory_from_friend $temp_restore_dir local/$USERNAME
cp -r $temp_restore_dir/home/$USERNAME/.local /home/$USERNAME/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
rm -rf /root/templocal rm -rf $temp_restore_dir
exit 664 exit 664
fi fi
rm -rf /root/templocal rm -rf $temp_restore_dir
fi fi
fi fi
done done
@ -639,15 +652,16 @@ function restore_personal_settings {
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
fi fi
echo $"Restoring personal settings for $USERNAME" echo $"Restoring personal settings for $USERNAME"
restore_directory_from_friend /root/temppersonal personal/$USERNAME temp_restore_dir=/root/temppersonal
restore_directory_from_friend $temp_restore_dir personal/$USERNAME
if [ -d /home/$USERNAME/personal ]; then if [ -d /home/$USERNAME/personal ]; then
rm -rf /home/$USERNAME/personal rm -rf /home/$USERNAME/personal
fi fi
mv /root/temppersonal/home/$USERNAME/personal /home/$USERNAME mv $temp_restore_dir/home/$USERNAME/personal /home/$USERNAME
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
exit 184 exit 184
fi fi
rm -rf /root/temppersonal rm -rf $temp_restore_dir
fi fi
fi fi
done done
@ -661,12 +675,13 @@ function restore_mailing_list {
fi fi
if [ -d /var/spool/mlmmj ]; then if [ -d /var/spool/mlmmj ]; then
echo $"Restoring public mailing list" echo $"Restoring public mailing list"
restore_directory_from_friend /root/tempmailinglist mailinglist temp_restore_dir=/root/tempmailinglist
cp -r /root/tempmailinglist/root/spool/mlmmj/* /var/spool/mlmmj restore_directory_from_friend $temp_restore_dir mailinglist
cp -r $temp_restore_dir/root/spool/mlmmj/* /var/spool/mlmmj
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
exit 526 exit 526
fi fi
rm -rf /root/tempmailinglist rm -rf $temp_restore_dir
fi fi
} }
@ -678,12 +693,13 @@ function restore_xmpp {
fi fi
if [ -d /var/lib/prosody ]; then if [ -d /var/lib/prosody ]; then
echo $"Restoring XMPP settings" echo $"Restoring XMPP settings"
restore_directory_from_friend /root/tempxmpp xmpp temp_restore_dir=/root/tempxmpp
cp -r /root/tempxmpp/var/lib/prosody/* /var/lib/prosody restore_directory_from_friend $temp_restore_dir xmpp
cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
exit 725 exit 725
fi fi
rm -rf /root/tempxmpp rm -rf $temp_restore_dir
service prosody restart service prosody restart
chown -R prosody:prosody /var/lib/prosody/* chown -R prosody:prosody /var/lib/prosody/*
fi fi
@ -767,28 +783,30 @@ function restore_syncthing {
if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then
echo $"Restoring syncthing configuration" echo $"Restoring syncthing configuration"
restore_directory_from_friend /root/tempsyncthingconfig syncthingconfig temp_restore_dir=/root/tempsyncthingconfig
cp -r /root/tempsyncthingconfig/* / restore_directory_from_friend $temp_restore_dir syncthingconfig
cp -r $temp_restore_dir/* /
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
unmount_drive unmount_drive
systemctl start syncthing systemctl start syncthing
systemctl start cron systemctl start cron
exit 6833 exit 6833
fi fi
rm -rf /root/tempsyncthingconfig rm -rf $temp_restore_dir
fi fi
if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
echo $"Restoring syncthing shared files" echo $"Restoring syncthing shared files"
restore_directory_from_friend /root/tempsyncthingshared syncthingshared temp_restore_dir=/root/tempsyncthingshared
cp -r /root/tempsyncthingshared/* / restore_directory_from_friend $temp_restore_dir syncthingshared
cp -r $temp_restore_dir/* /
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
unmount_drive unmount_drive
systemctl start syncthing systemctl start syncthing
systemctl start cron systemctl start cron
exit 37904 exit 37904
fi fi
rm -rf /root/tempsyncthingshared rm -rf $temp_restore_dir
fi fi
if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then
@ -799,16 +817,17 @@ function restore_syncthing {
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
fi fi
echo $"Restoring syncthing files for $USERNAME" echo $"Restoring syncthing files for $USERNAME"
restore_directory_from_friend /root/tempsyncthing syncthing/$USERNAME temp_restore_dir=/root/tempsyncthing
cp -r /root/tempsyncthing/home/$USERNAME/Sync /home/$USERNAME/ restore_directory_from_friend $temp_restore_dir syncthing/$USERNAME
cp -r $temp_restore_dir/home/$USERNAME/Sync /home/$USERNAME/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
rm -rf /root/tempsyncthing rm -rf $temp_restore_dir
unmount_drive unmount_drive
systemctl start syncthing systemctl start syncthing
systemctl start cron systemctl start cron
exit 68438 exit 68438
fi fi
rm -rf /root/tempsyncthing rm -rf $temp_restore_dir
# restore device IDs from config settings # restore device IDs from config settings
if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
@ -839,12 +858,13 @@ function restore_mediagoblin {
MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}') MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}')
if [ -d $SERVER_DIRECTORY/backup/mediagoblin ]; then if [ -d $SERVER_DIRECTORY/backup/mediagoblin ]; then
echo $"Restoring Mediagoblin installation" echo $"Restoring Mediagoblin installation"
restore_directory_from_friend /root/tempmediagoblin mediagoblin temp_restore_dir=/root/tempmediagoblin
cp -r /root/tempmediagoblin/* / restore_directory_from_friend $temp_restore_dir mediagoblin
cp -r $temp_restore_dir/* /
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
exit 5626 exit 5626
fi fi
rm -rf /root/tempmediagoblin rm -rf $temp_restore_dir
fi fi
chown -hR mediagoblin:www-data /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs chown -hR mediagoblin:www-data /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
fi fi
@ -940,14 +960,15 @@ function restore_blog {
if [ -d $SERVER_DIRECTORY/backup/blog ]; then if [ -d $SERVER_DIRECTORY/backup/blog ]; then
FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}') FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
echo $"Restoring blog installation $FULLBLOG_DOMAIN_NAME" echo $"Restoring blog installation $FULLBLOG_DOMAIN_NAME"
mkdir /root/tempblog temp_restore_dir=/root/tempblog
restore_directory_from_friend /root/tempblog blog mkdir $temp_restore_dir
restore_directory_from_friend $temp_restore_dir blog
rm -rf /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs rm -rf /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
cp -r /root/tempblog/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs /var/www/${FULLBLOG_DOMAIN_NAME}/ cp -r $temp_restore_dir/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs /var/www/${FULLBLOG_DOMAIN_NAME}/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
exit 593 exit 593
fi fi
rm -rf /root/tempblog rm -rf $temp_restore_dir
if [ ! -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content ]; then if [ ! -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content ]; then
echo $"No content directory found after restoring blog" echo $"No content directory found after restoring blog"
exit 287 exit 287
@ -978,13 +999,14 @@ function restore_cjdns {
fi fi
if [ -d $SERVER_DIRECTORY/backup/cjdns ]; then if [ -d $SERVER_DIRECTORY/backup/cjdns ]; then
echo $"Restoring cjdns installation" echo $"Restoring cjdns installation"
restore_directory_from_friend /root/tempcjdns cjdns temp_restore_dir=/root/tempcjdns
restore_directory_from_friend $temp_restore_dir cjdns
rm -rf /etc/cjdns rm -rf /etc/cjdns
cp -r /root/tempcjdns/etc/cjdns /etc/ cp -r $temp_restore_dir/etc/cjdns /etc/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
exit 7438 exit 7438
fi fi
rm -rf /root/tempcjdns rm -rf $temp_restore_dir
fi fi
} }
@ -996,23 +1018,24 @@ function restore_voip {
fi fi
if [ -d $SERVER_DIRECTORY/backup/voip ]; then if [ -d $SERVER_DIRECTORY/backup/voip ]; then
echo $"Restoring VoIP settings" echo $"Restoring VoIP settings"
restore_directory_from_friend /root/tempvoip voip temp_restore_dir=/root/tempvoip
cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/ restore_directory_from_friend $temp_restore_dir voip
cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
rm -rf /root/tempvoip rm -rf $temp_restore_dir
exit 7823 exit 7823
fi fi
cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
rm -rf /root/tempvoip rm -rf $temp_restore_dir
exit 7823 exit 7823
fi fi
cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/ cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
rm -rf /root/tempvoip rm -rf $temp_restore_dir
exit 276 exit 276
fi fi
rm -rf /root/tempvoip rm -rf $temp_restore_dir
cp /etc/ssl/certs/mumble* /var/lib/mumble-server cp /etc/ssl/certs/mumble* /var/lib/mumble-server
cp /etc/ssl/private/mumble* /var/lib/mumble-server cp /etc/ssl/private/mumble* /var/lib/mumble-server
chown -R mumble-server:mumble-server /var/lib/mumble-server chown -R mumble-server:mumble-server /var/lib/mumble-server
@ -1056,15 +1079,16 @@ function restore_email {
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
fi fi
echo $"Restoring emails for $USERNAME" echo $"Restoring emails for $USERNAME"
restore_directory_from_friend /root/tempmail mail/$USERNAME temp_restore_dir=/root/tempmail
restore_directory_from_friend $temp_restore_dir mail/$USERNAME
if [ ! -d /home/$USERNAME/Maildir ]; then if [ ! -d /home/$USERNAME/Maildir ]; then
mkdir /home/$USERNAME/Maildir mkdir /home/$USERNAME/Maildir
fi fi
tar -xzvf /root/tempmail/root/tempbackupemail/$USERNAME/maildir.tar.gz -C / tar -xzvf $temp_restore_dir/root/tempbackupemail/$USERNAME/maildir.tar.gz -C /
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
exit 927 exit 927
fi fi
rm -rf /root/tempmail rm -rf $temp_restore_dir
fi fi
fi fi
done done
@ -1079,12 +1103,13 @@ function restore_dlna {
if [ -d /var/cache/minidlna ]; then if [ -d /var/cache/minidlna ]; then
if [ -d $SERVER_DIRECTORY/backup/dlna ]; then if [ -d $SERVER_DIRECTORY/backup/dlna ]; then
echo $"Restoring DLNA cache" echo $"Restoring DLNA cache"
restore_directory_from_friend /root/tempdlna dlna temp_restore_dir=/root/tempdlna
cp -r /root/tempdlna/var/cache/minidlna/* /var/cache/minidlna/ restore_directory_from_friend $temp_restore_dir dlna
cp -r $temp_restore_dir/var/cache/minidlna/* /var/cache/minidlna/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
exit 982 exit 982
fi fi
rm -rf /root/tempdlna rm -rf $temp_restore_dir
fi fi
fi fi
} }