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,13 +137,7 @@ 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
|
||||
function restore_configuration {
|
||||
if [ -d $SERVER_DIRECTORY/backup/config ]; then
|
||||
echo $"Restoring configuration files"
|
||||
restore_directory_from_friend /root/tempconfig config
|
||||
|
@ -163,8 +159,9 @@ if [ -d $SERVER_DIRECTORY/backup/config ]; then
|
|||
fi
|
||||
rm -rf /root/tempconfig
|
||||
fi
|
||||
}
|
||||
|
||||
# Restore MariaDB
|
||||
function restore_mariadb {
|
||||
if [ -d $SERVER_DIRECTORY/backup/mariadb ]; then
|
||||
echo $"Restoring MariaDB settings"
|
||||
restore_directory_from_friend /root/tempmariadb mariadb
|
||||
|
@ -197,14 +194,16 @@ if [ -d $SERVER_DIRECTORY/backup/mariadb ]; then
|
|||
echo "$DATABASE_PASSWORD" > /root/dbpass
|
||||
chmod 600 /root/dbpass
|
||||
fi
|
||||
}
|
||||
|
||||
# restore Let's Encrypt
|
||||
function restore_letsencrypt {
|
||||
if [ -d $SERVER_DIRECTORY/backup/letsencrypt ]; then
|
||||
echo $"Restoring Lets Encrypt settings"
|
||||
restore_directory_from_friend / letsencrypt
|
||||
fi
|
||||
}
|
||||
|
||||
# restore mutt settings
|
||||
function restore_mutt_settings {
|
||||
for d in $SERVER_DIRECTORY/backup/mutt/*/ ; do
|
||||
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
|
||||
if [[ $USERNAME != "git" ]]; then
|
||||
|
@ -228,8 +227,9 @@ for d in $SERVER_DIRECTORY/backup/mutt/*/ ; do
|
|||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# restore user gpg keys
|
||||
function restore_gpg {
|
||||
for d in $SERVER_DIRECTORY/backup/gnupg/*/ ; do
|
||||
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
|
||||
if [[ $USERNAME != "git" ]]; then
|
||||
|
@ -254,8 +254,9 @@ for d in $SERVER_DIRECTORY/backup/gnupg/*/ ; do
|
|||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# restore user procmail
|
||||
function restore_procmail {
|
||||
for d in $SERVER_DIRECTORY/backup/procmail/*/ ; do
|
||||
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
|
||||
if [[ $USERNAME != "git" ]]; then
|
||||
|
@ -274,8 +275,9 @@ for d in $SERVER_DIRECTORY/backup/procmail/*/ ; do
|
|||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Restore user spam settings
|
||||
function restore_spamassassin {
|
||||
for d in $SERVER_DIRECTORY/backup/spamassassin/*/ ; do
|
||||
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
|
||||
if [[ $USERNAME != "git" ]]; then
|
||||
|
@ -294,8 +296,9 @@ for d in $SERVER_DIRECTORY/backup/spamassassin/*/ ; do
|
|||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Restore admin user README
|
||||
function restore_admin_readme {
|
||||
if [ -d $SERVER_DIRECTORY/backup/readme ]; then
|
||||
echo $"Restoring README"
|
||||
restore_directory_from_friend /root/tempreadme readme
|
||||
|
@ -306,8 +309,9 @@ if [ -d $SERVER_DIRECTORY/backup/readme ]; then
|
|||
fi
|
||||
rm -rf /root/tempreadme
|
||||
fi
|
||||
}
|
||||
|
||||
# restore IPFS
|
||||
function restore_ipfs {
|
||||
if [ -d $SERVER_DIRECTORY/backup/ipfs ]; then
|
||||
echo $"Restoring IPFS"
|
||||
restore_directory_from_friend /root/tempipfs ipfs
|
||||
|
@ -318,8 +322,9 @@ if [ -d $SERVER_DIRECTORY/backup/ipfs ]; then
|
|||
fi
|
||||
rm -rf /root/tempipfs
|
||||
fi
|
||||
}
|
||||
|
||||
# restore user ssh keys
|
||||
function restore_ssh_keys {
|
||||
for d in $SERVER_DIRECTORY/backup/ssh/*/ ; do
|
||||
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
|
||||
if [[ $USERNAME != "git" ]]; then
|
||||
|
@ -338,8 +343,9 @@ for d in $SERVER_DIRECTORY/backup/ssh/*/ ; do
|
|||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# restore user config files
|
||||
function restore_user_config {
|
||||
for d in $SERVER_DIRECTORY/backup/config/*/ ; do
|
||||
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
|
||||
if [[ $USERNAME != "git" ]]; then
|
||||
|
@ -358,8 +364,9 @@ for d in $SERVER_DIRECTORY/backup/config/*/ ; do
|
|||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# restore certs
|
||||
function restore_certs {
|
||||
if [ -d $SERVER_DIRECTORY/backup/ssl ]; then
|
||||
echo $"Restoring certificates"
|
||||
restore_directory_from_friend /root/tempssl ssl
|
||||
|
@ -369,8 +376,9 @@ if [ -d $SERVER_DIRECTORY/backup/ssl ]; then
|
|||
fi
|
||||
rm -rf /root/tempssl
|
||||
fi
|
||||
}
|
||||
|
||||
# restore personal settings
|
||||
function restore_personal_settings {
|
||||
for d in $SERVER_DIRECTORY/backup/personal/*/ ; do
|
||||
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
|
||||
if [[ $USERNAME != "git" ]]; then
|
||||
|
@ -391,8 +399,9 @@ for d in $SERVER_DIRECTORY/backup/personal/*/ ; do
|
|||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# restore mailing list
|
||||
function restore_mailing_list {
|
||||
if [ -d /var/spool/mlmmj ]; then
|
||||
echo $"Restoring public mailing list"
|
||||
restore_directory_from_friend /root/tempmailinglist mailinglist
|
||||
|
@ -402,8 +411,9 @@ if [ -d /var/spool/mlmmj ]; then
|
|||
fi
|
||||
rm -rf /root/tempmailinglist
|
||||
fi
|
||||
}
|
||||
|
||||
# restore XMPP
|
||||
function restore_xmpp {
|
||||
if [ -d /var/lib/prosody ]; then
|
||||
echo $"Restoring XMPP settings"
|
||||
restore_directory_from_friend /root/tempxmpp xmpp
|
||||
|
@ -415,8 +425,9 @@ if [ -d /var/lib/prosody ]; then
|
|||
service prosody restart
|
||||
chown -R prosody:prosody /var/lib/prosody/*
|
||||
fi
|
||||
}
|
||||
|
||||
# restore gnu social
|
||||
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}
|
||||
|
@ -424,8 +435,9 @@ if grep -q "GNU Social domain" $COMPLETION_FILE; then
|
|||
rm -rf /root/tempgnusocial
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore hubzilla
|
||||
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}
|
||||
|
@ -440,8 +452,9 @@ if grep -q "Hubzilla domain" $COMPLETION_FILE; then
|
|||
rm -rf /root/temphubzilla
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore owncloud
|
||||
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
|
||||
|
@ -470,8 +483,9 @@ if grep -q "Owncloud domain" $COMPLETION_FILE; then
|
|||
ln -s /usr/share/owncloud /var/www/${OWNCLOUD_DOMAIN_NAME}/htdocs
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore gogs
|
||||
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
|
||||
|
@ -504,8 +518,9 @@ if grep -q "Gogs domain" $COMPLETION_FILE; then
|
|||
chown -R git:git /home/git
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore wiki
|
||||
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"
|
||||
|
@ -531,8 +546,9 @@ if [ -d $SERVER_DIRECTORY/backup/wiki ]; then
|
|||
ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${WIKI_DOMAIN_NAME}.pem
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore blog
|
||||
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"
|
||||
|
@ -564,8 +580,9 @@ if [ -d $SERVER_DIRECTORY/backup/blog ]; then
|
|||
ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${FULLBLOG_DOMAIN_NAME}.pem
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore cjdns
|
||||
function restore_cjdns {
|
||||
if [ -d $SERVER_DIRECTORY/backup/cjdns ]; then
|
||||
echo $"Restoring cjdns installation"
|
||||
restore_directory_from_friend /root/tempcjdns cjdns
|
||||
|
@ -576,8 +593,9 @@ if [ -d $SERVER_DIRECTORY/backup/cjdns ]; then
|
|||
fi
|
||||
rm -rf /root/tempcjdns
|
||||
fi
|
||||
}
|
||||
|
||||
# restore voip
|
||||
function restore_voip {
|
||||
if [ -d $SERVER_DIRECTORY/backup/voip ]; then
|
||||
echo $"Restoring VoIP settings"
|
||||
restore_directory_from_friend /root/tempvoip voip
|
||||
|
@ -603,8 +621,9 @@ if [ -d $SERVER_DIRECTORY/backup/voip ]; then
|
|||
service sipwitch restart
|
||||
service mumble-server restart
|
||||
fi
|
||||
}
|
||||
|
||||
# Restore tox
|
||||
function restore_tox {
|
||||
if [ -d $SERVER_DIRECTORY/backup/tox ]; then
|
||||
echo $"Restoring Tox node settings"
|
||||
restore_directory_from_friend / tox
|
||||
|
@ -618,8 +637,9 @@ if [ -d $SERVER_DIRECTORY/backup/tox ]; then
|
|||
exit 59369
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore email
|
||||
function restore_email {
|
||||
for d in $SERVER_DIRECTORY/backup/mail/*/ ; do
|
||||
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
|
||||
if [[ $USERNAME != "git" ]]; then
|
||||
|
@ -640,8 +660,9 @@ for d in $SERVER_DIRECTORY/backup/mail/*/ ; do
|
|||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Restore DLNA
|
||||
function restore_dlna {
|
||||
if [ -d /var/cache/minidlna ]; then
|
||||
if [ -d $SERVER_DIRECTORY/backup/dlna ]; then
|
||||
echo $"Restoring DLNA cache"
|
||||
|
@ -653,6 +674,39 @@ if [ -d /var/cache/minidlna ]; then
|
|||
rm -rf /root/tempdlna
|
||||
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