Tidying of remote restore
This commit is contained in:
parent
7eef20071f
commit
cfbe634643
|
@ -43,24 +43,26 @@ ADMIN_EMAIL_ADDRESS=${ADMIN_USERNAME}@${HOSTNAME}
|
|||
# Temporary location for data to be backed up to other servers
|
||||
SERVER_DIRECTORY=/root/remoterestore
|
||||
|
||||
BACKUP_LIST=/home/${ADMIN_USERNAME}/backup.list
|
||||
|
||||
if [ ! $SERVER_NAME ]; then
|
||||
echo $'restorefromfriend [server]'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f /home/${ADMIN_USERNAME}/backup.list ]; then
|
||||
echo $"No friends list found at /home/${ADMIN_USERNAME}/backup.list"
|
||||
if [ ! -f $BACKUP_LIST ]; then
|
||||
echo $"No friends list found at $BACKUP_LIST"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if ! grep -q "$SERVER_NAME" /home/${ADMIN_USERNAME}/backup.list; then
|
||||
if ! grep -q "$SERVER_NAME" $BACKUP_LIST; then
|
||||
echo $"Server not found within the friends list"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
REMOTE_SERVER=$(grep -i "$SERVER_NAME" /home/${ADMIN_USERNAME}/backup.list | awk -F ' ' '{print $1}')
|
||||
REMOTE_SSH_PORT=$(grep -i "$SERVER_NAME" /home/${ADMIN_USERNAME}/backup.list | awk -F ' ' '{print $2}')
|
||||
REMOTE_PASSWORD=$(grep -i "$SERVER_NAME" /home/${ADMIN_USERNAME}/backup.list | awk -F ' ' '{print $3}')
|
||||
REMOTE_SERVER=$(grep -i "$SERVER_NAME" $BACKUP_LIST | awk -F ' ' '{print $1}')
|
||||
REMOTE_SSH_PORT=$(grep -i "$SERVER_NAME" $BACKUP_LIST | awk -F ' ' '{print $2}')
|
||||
REMOTE_PASSWORD=$(grep -i "$SERVER_NAME" $BACKUP_LIST | awk -F ' ' '{print $3}')
|
||||
|
||||
NOW=$(date +"%Y-%m-%d %H:%M:%S")
|
||||
|
||||
|
@ -135,14 +137,8 @@ function restore_database_from_friend {
|
|||
fi
|
||||
}
|
||||
|
||||
# Social key management
|
||||
# Recover any key fragments and reconstruct the gpg key
|
||||
${PROJECT_NAME}-recoverkey -u ${ADMIN_USERNAME} -l /home/${ADMIN_USERNAME}/backup.list
|
||||
|
||||
copy_gpg_keys
|
||||
|
||||
# Restore configuration files
|
||||
if [ -d $SERVER_DIRECTORY/backup/config ]; then
|
||||
function restore_configuration {
|
||||
if [ -d $SERVER_DIRECTORY/backup/config ]; then
|
||||
echo $"Restoring configuration files"
|
||||
restore_directory_from_friend /root/tempconfig config
|
||||
cp -f /root/tempconfig/root/${PROJECT_NAME}.cfg $CONFIG_FILE
|
||||
|
@ -162,10 +158,11 @@ if [ -d $SERVER_DIRECTORY/backup/config ]; then
|
|||
exit 7252
|
||||
fi
|
||||
rm -rf /root/tempconfig
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Restore MariaDB
|
||||
if [ -d $SERVER_DIRECTORY/backup/mariadb ]; then
|
||||
function restore_mariadb {
|
||||
if [ -d $SERVER_DIRECTORY/backup/mariadb ]; then
|
||||
echo $"Restoring MariaDB settings"
|
||||
restore_directory_from_friend /root/tempmariadb mariadb
|
||||
echo $"Get the MariaDB password from the backup"
|
||||
|
@ -196,16 +193,18 @@ if [ -d $SERVER_DIRECTORY/backup/mariadb ]; then
|
|||
# Change database password file
|
||||
echo "$DATABASE_PASSWORD" > /root/dbpass
|
||||
chmod 600 /root/dbpass
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore Let's Encrypt
|
||||
if [ -d $SERVER_DIRECTORY/backup/letsencrypt ]; then
|
||||
function restore_letsencrypt {
|
||||
if [ -d $SERVER_DIRECTORY/backup/letsencrypt ]; then
|
||||
echo $"Restoring Lets Encrypt settings"
|
||||
restore_directory_from_friend / letsencrypt
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore mutt settings
|
||||
for d in $SERVER_DIRECTORY/backup/mutt/*/ ; do
|
||||
function restore_mutt_settings {
|
||||
for d in $SERVER_DIRECTORY/backup/mutt/*/ ; do
|
||||
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
|
||||
if [[ $USERNAME != "git" ]]; then
|
||||
if [ -d $SERVER_DIRECTORY/backup/mutt/$USERNAME ]; then
|
||||
|
@ -227,10 +226,11 @@ for d in $SERVER_DIRECTORY/backup/mutt/*/ ; do
|
|||
rm -rf /root/tempmutt
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# restore user gpg keys
|
||||
for d in $SERVER_DIRECTORY/backup/gnupg/*/ ; do
|
||||
function restore_gpg {
|
||||
for d in $SERVER_DIRECTORY/backup/gnupg/*/ ; do
|
||||
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
|
||||
if [[ $USERNAME != "git" ]]; then
|
||||
if [ -d $SERVER_DIRECTORY/backup/gnupg/$USERNAME ]; then
|
||||
|
@ -253,10 +253,11 @@ for d in $SERVER_DIRECTORY/backup/gnupg/*/ ; do
|
|||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# restore user procmail
|
||||
for d in $SERVER_DIRECTORY/backup/procmail/*/ ; do
|
||||
function restore_procmail {
|
||||
for d in $SERVER_DIRECTORY/backup/procmail/*/ ; do
|
||||
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
|
||||
if [[ $USERNAME != "git" ]]; then
|
||||
if [ -d $SERVER_DIRECTORY/backup/procmail/$USERNAME ]; then
|
||||
|
@ -273,10 +274,11 @@ for d in $SERVER_DIRECTORY/backup/procmail/*/ ; do
|
|||
rm -rf /root/tempprocmail
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# Restore user spam settings
|
||||
for d in $SERVER_DIRECTORY/backup/spamassassin/*/ ; do
|
||||
function restore_spamassassin {
|
||||
for d in $SERVER_DIRECTORY/backup/spamassassin/*/ ; do
|
||||
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
|
||||
if [[ $USERNAME != "git" ]]; then
|
||||
if [ -d $SERVER_DIRECTORY/backup/spamassassin/$USERNAME ]; then
|
||||
|
@ -293,10 +295,11 @@ for d in $SERVER_DIRECTORY/backup/spamassassin/*/ ; do
|
|||
rm -rf /root/tempspamassassin
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# Restore admin user README
|
||||
if [ -d $SERVER_DIRECTORY/backup/readme ]; then
|
||||
function restore_admin_readme {
|
||||
if [ -d $SERVER_DIRECTORY/backup/readme ]; then
|
||||
echo $"Restoring README"
|
||||
restore_directory_from_friend /root/tempreadme readme
|
||||
cp -f /root/tempreadme/home/$ADMIN_USERNAME/tempbackup/README /home/$ADMIN_USERNAME/
|
||||
|
@ -305,10 +308,11 @@ if [ -d $SERVER_DIRECTORY/backup/readme ]; then
|
|||
exit 276
|
||||
fi
|
||||
rm -rf /root/tempreadme
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore IPFS
|
||||
if [ -d $SERVER_DIRECTORY/backup/ipfs ]; then
|
||||
function restore_ipfs {
|
||||
if [ -d $SERVER_DIRECTORY/backup/ipfs ]; then
|
||||
echo $"Restoring IPFS"
|
||||
restore_directory_from_friend /root/tempipfs ipfs
|
||||
cp -rf /root/tempipfs/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs
|
||||
|
@ -317,10 +321,11 @@ if [ -d $SERVER_DIRECTORY/backup/ipfs ]; then
|
|||
exit 276
|
||||
fi
|
||||
rm -rf /root/tempipfs
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore user ssh keys
|
||||
for d in $SERVER_DIRECTORY/backup/ssh/*/ ; do
|
||||
function restore_ssh_keys {
|
||||
for d in $SERVER_DIRECTORY/backup/ssh/*/ ; do
|
||||
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
|
||||
if [[ $USERNAME != "git" ]]; then
|
||||
if [ -d $SERVER_DIRECTORY/backup/ssh/$USERNAME ]; then
|
||||
|
@ -337,10 +342,11 @@ for d in $SERVER_DIRECTORY/backup/ssh/*/ ; do
|
|||
rm -rf /root/tempssh
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# restore user config files
|
||||
for d in $SERVER_DIRECTORY/backup/config/*/ ; do
|
||||
function restore_user_config {
|
||||
for d in $SERVER_DIRECTORY/backup/config/*/ ; do
|
||||
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
|
||||
if [[ $USERNAME != "git" ]]; then
|
||||
if [ -d $SERVER_DIRECTORY/backup/config/$USERNAME ]; then
|
||||
|
@ -357,10 +363,11 @@ for d in $SERVER_DIRECTORY/backup/config/*/ ; do
|
|||
rm -rf /root/tempconfig
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# restore certs
|
||||
if [ -d $SERVER_DIRECTORY/backup/ssl ]; then
|
||||
function restore_certs {
|
||||
if [ -d $SERVER_DIRECTORY/backup/ssl ]; then
|
||||
echo $"Restoring certificates"
|
||||
restore_directory_from_friend /root/tempssl ssl
|
||||
cp -r /root/tempssl/etc/ssl/* /etc/ssl
|
||||
|
@ -368,10 +375,11 @@ if [ -d $SERVER_DIRECTORY/backup/ssl ]; then
|
|||
exit 276
|
||||
fi
|
||||
rm -rf /root/tempssl
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore personal settings
|
||||
for d in $SERVER_DIRECTORY/backup/personal/*/ ; do
|
||||
function restore_personal_settings {
|
||||
for d in $SERVER_DIRECTORY/backup/personal/*/ ; do
|
||||
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
|
||||
if [[ $USERNAME != "git" ]]; then
|
||||
if [ -d $SERVER_DIRECTORY/backup/personal/$USERNAME ]; then
|
||||
|
@ -390,10 +398,11 @@ for d in $SERVER_DIRECTORY/backup/personal/*/ ; do
|
|||
rm -rf /root/temppersonal
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# restore mailing list
|
||||
if [ -d /var/spool/mlmmj ]; then
|
||||
function restore_mailing_list {
|
||||
if [ -d /var/spool/mlmmj ]; then
|
||||
echo $"Restoring public mailing list"
|
||||
restore_directory_from_friend /root/tempmailinglist mailinglist
|
||||
cp -r /root/tempmailinglist/root/spool/mlmmj/* /var/spool/mlmmj
|
||||
|
@ -401,10 +410,11 @@ if [ -d /var/spool/mlmmj ]; then
|
|||
exit 526
|
||||
fi
|
||||
rm -rf /root/tempmailinglist
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore XMPP
|
||||
if [ -d /var/lib/prosody ]; then
|
||||
function restore_xmpp {
|
||||
if [ -d /var/lib/prosody ]; then
|
||||
echo $"Restoring XMPP settings"
|
||||
restore_directory_from_friend /root/tempxmpp xmpp
|
||||
cp -r /root/tempxmpp/var/lib/prosody/* /var/lib/prosody
|
||||
|
@ -414,19 +424,21 @@ if [ -d /var/lib/prosody ]; then
|
|||
rm -rf /root/tempxmpp
|
||||
service prosody restart
|
||||
chown -R prosody:prosody /var/lib/prosody/*
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore gnu social
|
||||
if grep -q "GNU Social domain" $COMPLETION_FILE; then
|
||||
function restore_gnu_social {
|
||||
if grep -q "GNU Social domain" $COMPLETION_FILE; then
|
||||
MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
|
||||
restore_database_from_friend gnusocial ${MICROBLOG_DOMAIN_NAME}
|
||||
if [ -d /root/tempgnusocial ]; then
|
||||
rm -rf /root/tempgnusocial
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore hubzilla
|
||||
if grep -q "Hubzilla domain" $COMPLETION_FILE; then
|
||||
function restore_hubzilla {
|
||||
if grep -q "Hubzilla domain" $COMPLETION_FILE; then
|
||||
HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
|
||||
restore_database_from_friend hubzilla ${HUBZILLA_DOMAIN_NAME}
|
||||
if [ -d $SERVER_DIRECTORY/backup/hubzilla ]; then
|
||||
|
@ -439,10 +451,11 @@ if grep -q "Hubzilla domain" $COMPLETION_FILE; then
|
|||
if [ -d /root/temphubzilla ]; then
|
||||
rm -rf /root/temphubzilla
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore owncloud
|
||||
if grep -q "Owncloud domain" $COMPLETION_FILE; then
|
||||
function restore_owncloud {
|
||||
if grep -q "Owncloud domain" $COMPLETION_FILE; then
|
||||
OWNCLOUD_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Owncloud domain" | awk -F ':' '{print $2}')
|
||||
restore_database_from_friend owncloud $OWNCLOUD_DOMAIN_NAME
|
||||
if [ -d $SERVER_DIRECTORY/backup/owncloud ]; then
|
||||
|
@ -469,10 +482,11 @@ if grep -q "Owncloud domain" $COMPLETION_FILE; then
|
|||
done
|
||||
ln -s /usr/share/owncloud /var/www/${OWNCLOUD_DOMAIN_NAME}/htdocs
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore gogs
|
||||
if grep -q "Gogs domain" $COMPLETION_FILE; then
|
||||
function restore_gogs {
|
||||
if grep -q "Gogs domain" $COMPLETION_FILE; then
|
||||
GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
|
||||
restore_database_from_friend gogs $GIT_DOMAIN_NAME
|
||||
if [ -d $SERVER_DIRECTORY/backup/gogs ]; then
|
||||
|
@ -503,10 +517,11 @@ if grep -q "Gogs domain" $COMPLETION_FILE; then
|
|||
rm -rf /root/tempgogsssh
|
||||
chown -R git:git /home/git
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore wiki
|
||||
if [ -d $SERVER_DIRECTORY/backup/wiki ]; then
|
||||
function restore_wiki {
|
||||
if [ -d $SERVER_DIRECTORY/backup/wiki ]; then
|
||||
WIKI_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Wiki domain" | awk -F ':' '{print $2}')
|
||||
echo $"Restoring Wiki installation $WIKI_DOMAIN_NAME"
|
||||
restore_directory_from_friend /root/tempwiki wiki
|
||||
|
@ -530,10 +545,11 @@ if [ -d $SERVER_DIRECTORY/backup/wiki ]; then
|
|||
ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${WIKI_DOMAIN_NAME}.key
|
||||
ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${WIKI_DOMAIN_NAME}.pem
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore blog
|
||||
if [ -d $SERVER_DIRECTORY/backup/blog ]; then
|
||||
function restore_blog {
|
||||
if [ -d $SERVER_DIRECTORY/backup/blog ]; then
|
||||
FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
|
||||
echo $"Restoring blog installation $FULLBLOG_DOMAIN_NAME"
|
||||
mkdir /root/tempblog
|
||||
|
@ -563,10 +579,11 @@ if [ -d $SERVER_DIRECTORY/backup/blog ]; then
|
|||
ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${FULLBLOG_DOMAIN_NAME}.key
|
||||
ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${FULLBLOG_DOMAIN_NAME}.pem
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore cjdns
|
||||
if [ -d $SERVER_DIRECTORY/backup/cjdns ]; then
|
||||
function restore_cjdns {
|
||||
if [ -d $SERVER_DIRECTORY/backup/cjdns ]; then
|
||||
echo $"Restoring cjdns installation"
|
||||
restore_directory_from_friend /root/tempcjdns cjdns
|
||||
rm -rf /etc/cjdns
|
||||
|
@ -575,10 +592,11 @@ if [ -d $SERVER_DIRECTORY/backup/cjdns ]; then
|
|||
exit 7438
|
||||
fi
|
||||
rm -rf /root/tempcjdns
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore voip
|
||||
if [ -d $SERVER_DIRECTORY/backup/voip ]; then
|
||||
function restore_voip {
|
||||
if [ -d $SERVER_DIRECTORY/backup/voip ]; then
|
||||
echo $"Restoring VoIP settings"
|
||||
restore_directory_from_friend /root/tempvoip voip
|
||||
cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/
|
||||
|
@ -602,10 +620,11 @@ if [ -d $SERVER_DIRECTORY/backup/voip ]; then
|
|||
chown -R mumble-server:mumble-server /var/lib/mumble-server
|
||||
service sipwitch restart
|
||||
service mumble-server restart
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Restore tox
|
||||
if [ -d $SERVER_DIRECTORY/backup/tox ]; then
|
||||
function restore_tox {
|
||||
if [ -d $SERVER_DIRECTORY/backup/tox ]; then
|
||||
echo $"Restoring Tox node settings"
|
||||
restore_directory_from_friend / tox
|
||||
if [ ! "$?" = "0" ]; then
|
||||
|
@ -617,10 +636,11 @@ if [ -d $SERVER_DIRECTORY/backup/tox ]; then
|
|||
systemctl status tox-bootstrapd.service
|
||||
exit 59369
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore email
|
||||
for d in $SERVER_DIRECTORY/backup/mail/*/ ; do
|
||||
function restore_email {
|
||||
for d in $SERVER_DIRECTORY/backup/mail/*/ ; do
|
||||
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
|
||||
if [[ $USERNAME != "git" ]]; then
|
||||
if [ -d $SERVER_DIRECTORY/backup/mail/$USERNAME ]; then
|
||||
|
@ -639,10 +659,11 @@ for d in $SERVER_DIRECTORY/backup/mail/*/ ; do
|
|||
rm -rf /root/tempmail
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# Restore DLNA
|
||||
if [ -d /var/cache/minidlna ]; then
|
||||
function restore_dlna {
|
||||
if [ -d /var/cache/minidlna ]; then
|
||||
if [ -d $SERVER_DIRECTORY/backup/dlna ]; then
|
||||
echo $"Restoring DLNA cache"
|
||||
restore_directory_from_friend /root/tempdlna dlna
|
||||
|
@ -652,7 +673,40 @@ if [ -d /var/cache/minidlna ]; then
|
|||
fi
|
||||
rm -rf /root/tempdlna
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Social key management
|
||||
# Recover any key fragments and reconstruct the gpg key
|
||||
${PROJECT_NAME}-recoverkey -u ${ADMIN_USERNAME} -l $BACKUP_LIST
|
||||
|
||||
copy_gpg_keys
|
||||
restore_configuration
|
||||
restore_mariadb
|
||||
restore_letsencrypt
|
||||
restore_mutt_settings
|
||||
restore_gpg
|
||||
restore_procmail
|
||||
restore_spamassassin
|
||||
restore_admin_readme
|
||||
restore_ipfs
|
||||
restore_ssh_keys
|
||||
restore_user_config
|
||||
restore_certs
|
||||
restore_personal_settings
|
||||
restore_mailing_list
|
||||
restore_xmpp
|
||||
restore_gnu_social
|
||||
restore_hubzilla
|
||||
restore_owncloud
|
||||
restore_gogs
|
||||
restore_wiki
|
||||
restore_blog
|
||||
restore_cjdns
|
||||
restore_voip
|
||||
restore_tox
|
||||
restore_email
|
||||
restore_dlna
|
||||
|
||||
echo $"*** Remote restore was successful ***"
|
||||
|
||||
|
|
Loading…
Reference in New Issue