Create directories if needed

This commit is contained in:
Bob Mottram 2015-12-08 17:41:37 +00:00
parent 6764a366af
commit 10f1272645
2 changed files with 40 additions and 109 deletions

View File

@ -71,6 +71,9 @@ function backup_directory_to_friend {
exit 43382
fi
ADMIN_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
if [ ! -d $SERVER_DIRECTORY/backup/${2} ]; then
mkdir -p $SERVER_DIRECTORY/backup/${2}
fi
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
@ -123,36 +126,24 @@ for d in /home/*/ ; do
# 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
@ -166,9 +157,6 @@ for d in /home/*/ ; do
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
@ -179,18 +167,12 @@ for d in /home/*/ ; do
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
@ -202,9 +184,6 @@ for d in /home/*/ ; do
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
@ -246,9 +225,6 @@ 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"
@ -258,12 +234,6 @@ 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"
@ -276,12 +246,6 @@ if [ -d /home/git/go/src/github.com/gogits ]; then
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
@ -291,9 +255,6 @@ fi
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
@ -305,45 +266,30 @@ 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
@ -354,18 +300,12 @@ 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
@ -378,18 +318,12 @@ if [ -f /etc/mumble-server.ini ]; then
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
@ -399,9 +333,6 @@ 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