mkdir -p $RESTOREDIR
}
+# Setup environment for the backups for a service
+function hydra_backup_environment_service {
+ # Check restore strategy.
+ if [ "$HOST" == "localhost" ] || [ "$HOST" == "`facter hostname`" ]; then
+ hydra_backup_environment_local
+ else
+ hydra_backup_environment_remote $HOST restore
+ fi
+
+ # Check if folder exist on the backup.
+ if [ ! -d "$RESTOREDIR/$SERVICE_DIR" ]; then
+ echo "Service folder does not exist: $RESTOREDIR/$SERVICE_DIR"
+ exit 1
+ fi
+
+ # Set user.
+ if hydra_check_user $SERVICE_USER; then
+ SERVICE_USER="$SERVICE_USER"
+ else
+ SERVICE_USER="root"
+ fi
+
+ # Set group.
+ if hydra_check_group $SERVICE_GROUP; then
+ SERVICE_GROUP="$SERVICE_GROUP"
+ else
+ SERVICE_GROUP="root"
+ fi
+
+ # TODO: Backup it?
+ #hydractl backup-$SERVICE
+}
+
# Restore a database
function hydra_backup_restore_database {
DATABASE="$1"
# Parameters.
DATE="`date +%Y%m%d`"
-EMAIL_DIR="/var/mail/virtual"
+HOST="$1"
+SERVICE="email"
+SERVICE_DIR="/var/mail/virtual"
+SERVICE_USER="vmail"
+SERVICE_GROUP="vmail"
-# Check restore strategy.
-if [ "$1" == "localhost" ] || [ "$1" == "`facter hostname`" ]; then
- hydra_backup_environment_local
-else
- hydra_backup_environment_remote $1 restore
-fi
-
-# Check if folder exist on the backup.
-if [ ! -d "$RESTOREDIR/$EMAIL_DIR" ]; then
- echo "Email folder does not exist: $RESTOREDIR/$EMAIL_DIR"
- exit 1
-fi
-
-# Set git user.
-if hydra_check_user vmail; then
- EMAIL_USER="vmail"
-else
- EMAIL_USER="root"
-fi
-
-# Set git group.
-if hydra_check_group vmail; then
- EMAIL_GROUP="vmail"
-else
- EMAIL_GROUP="root"
-fi
-
-# TODO: Backup it?
-#hydractl backup-email
+# Set restore environment.
+hydra_backup_environment_service
# Restore email folder from backup.
#
# Symlink creation on site instances like drupal should be done
# already by backup-restore-site.
-for folder in `ls $RESTOREDIR/$EMAIL_DIR`; do
- if [ -d "$EMAIL_DIR/$folder" ]; then
- echo "Email for user $email already exists on $EMAIL_DIR/$folder!"
+for folder in `ls $RESTOREDIR/$SERVICE_DIR`; do
+ if [ -d "$SERVICE_DIR/$folder" ]; then
+ echo "Email for user $email already exists on $SERVICE_DIR/$folder!"
else
- echo "Processing $EMAIL_DIR/$folder..."
- cp -a $RESTOREDIR/$EMAIL_DIR/$folder $EMAIL_DIR/$folder
+ echo "Processing $SERVICE_DIR/$folder..."
+ cp -a $RESTOREDIR/$SERVICE_DIR/$folder $SERVICE_DIR/$folder
fi
done
# Fix permissions.
-chown -R $EMAIL_USER.$EMAIL_GROUP $EMAIL_DIR
+chown -R $SERVICE_USER.$SERVICE_GROUP $SERVICE_DIR
# Parameters.
DATE="`date +%Y%m%d`"
-LISTS_DIR="/var/lib/firma/lists"
+HOST="$1"
+SERVICE="firma"
+SERVICE_DIR="/var/lib/firma/lists"
+SERVICE_USER="firma"
+SERVICE_GROUP="firma"
-# Check restore strategy.
-if [ "$1" == "localhost" ] || [ "$1" == "`facter hostname`" ]; then
- hydra_backup_environment_local
-else
- hydra_backup_environment_remote $1 restore
-fi
-
-# Check if folder exist on the backup.
-if [ ! -d "$RESTOREDIR/$LISTS_DIR" ]; then
- echo "Lists folder does not exist: $RESTOREDIR/$LISTS_DIR"
- exit 1
-fi
-
-# Set git user.
-if hydra_check_user firma; then
- LISTS_USER="firma"
-else
- LISTS_USER="root"
-fi
-
-# Set git group.
-if hydra_check_group firma; then
- LISTS_GROUP="firma"
-else
- LISTS_GROUP="root"
-fi
-
-# TODO: Backup it?
-#hydractl backup-firma
+# Set restore environment.
+hydra_backup_environment_service
# Restore lists folders from backup.
-rsync -av --delete $RESTOREDIR/$LISTS_DIR/ $LISTS_DIR/
+rsync -av --delete $RESTOREDIR/$SERVICE_DIR/ $SERVICE_DIR/
# Fix permissions.
-chown -R $LISTS_USER.$LISTS_GROUP $LISTS_DIR
+chown -R $SERVICE_USER.$SERVICE_GROUP $SERVICE_DIR
hydra_config_load
# Parameters.
-DATE="`date +%Y%m%d`"
+HOST="$1"
+SERVICE="git"
+SERVICE_DIR="/var/git"
+SERVICE_USER="gitosis"
+SERVICE_GROUP="gitosis"
-# Check restore strategy.
-if [ "$1" == "localhost" ] || [ "$1" == "`facter hostname`" ]; then
- hydra_backup_environment_local
-else
- hydra_backup_environment_remote $1 restore
-fi
-
-# Check if folder exist on the backup.
-if [ ! -d "$RESTOREDIR/var/git" ]; then
- echo "Git folder does not exist: $RESTOREDIR/var/git"
- exit 1
-fi
-
-# Set git user.
-if hydra_check_user gitosis; then
- GIT_USER="gitosis"
-else
- GIT_USER="root"
-fi
-
-# Set git group.
-if hydra_check_group gitosis; then
- GIT_GROUP="gitosis"
-else
- GIT_GROUP="root"
-fi
+# Set restore environment.
+hydra_backup_environment_service
# Backup it.
+# TODO: directly at hydra_backup_environment_service
hydractl backup-site git
# Copy site folder from backup.
-cp -a $RESTOREDIR/var/git /var/git
+cp -a $RESTOREDIR/$SERVICE_DIR $SERVICE_DIR
# Fix permissions.
-chown -R $GIT_USER.$GIT_GROUP /var/git
+chown -R $GIT_USER.$GIT_GROUP $SERVICE_DIR
# Parameters.
DATE="`date +%Y%m%d`"
-LISTS_DIR="/var/spool/mlmmj"
+HOST="$1"
+SERVICE="mlmmj"
+SERVICE_DIR="/var/spool/mlmmj"
+SERVICE_USER="mlmmj"
+SERVICE_GROUP="mlmmj"
-# Check restore strategy.
-if [ "$1" == "localhost" ] || [ "$1" == "`facter hostname`" ]; then
- hydra_backup_environment_local
-else
- hydra_backup_environment_remote $1 restore
-fi
-
-# Check if folder exist on the backup.
-if [ ! -d "$RESTOREDIR/$LISTS_DIR" ]; then
- echo "Lists folder does not exist: $RESTOREDIR/$LISTS_DIR"
- exit 1
-fi
-
-# Set git user.
-if hydra_check_user mlmmj; then
- LISTS_USER="mlmmj"
-else
- LISTS_USER="root"
-fi
-
-# Set git group.
-if hydra_check_group mlmmj; then
- LISTS_GROUP="mlmmj"
-else
- LISTS_GROUP="root"
-fi
-
-# TODO: Backup it?
-#hydractl backup-mlmmj
+# Set restore environment.
+hydra_backup_environment_service
# Restore lists folders from backup.
-rsync -av --delete $RESTOREDIR/$LISTS_DIR/ $LISTS_DIR/
+rsync -av --delete $RESTOREDIR/$SERVICE_DIR/ $SERVICE_DIR/
# Fix permissions.
-chown -R $LISTS_USER.$LISTS_GROUP $LISTS_DIR
+chown -R $SERVICE_USER.$SERVICE_GROUP $SERVICE_DIR
# Parameters.
DATE="`date +%Y%m%d`"
-LISTS_DIR="/var/lib/schleuder"
+HOST="$1"
CONF_DIR="/etc/schleuder"
+SERVICE="schleuder"
+SERVICE_DIR="/var/lib/schleuder"
+SERVICE_USER="schleuder"
+SERVICE_GROUP="schleuder"
-# Check restore strategy.
-if [ "$1" == "localhost" ] || [ "$1" == "`facter hostname`" ]; then
- hydra_backup_environment_local
-else
- hydra_backup_environment_remote $1 restore
-fi
-
-# Check if folder exist on the backup.
-if [ ! -d "$RESTOREDIR/$LISTS_DIR" ]; then
- echo "Lists folder does not exist: $RESTOREDIR/$LISTS_DIR"
- exit 1
-fi
-
-# Set git user.
-if hydra_check_user schleuder; then
- LISTS_USER="schleuder"
-else
- LISTS_USER="root"
-fi
-
-# Set git group.
-if hydra_check_group schleuder; then
- LISTS_GROUP="schleuder"
-else
- LISTS_GROUP="root"
-fi
-
-# TODO: Backup it?
-#hydractl backup-schleuder
+# Set restore environment.
+hydra_backup_environment_service
# Restore lists folders from backup.
-rsync -av --delete $RESTOREDIR/$LISTS_DIR/ $LISTS_DIR/
+rsync -av --delete $RESTOREDIR/$SERVICE_DIR/ $SERVICE_DIR/
rsync -av --delete $RESTOREDIR/$CONF_DIR/ $CONF_DIR/
# Fix permissions.
-chown -R $LISTS_USER.$LISTS_GROUP $LISTS_DIR
+chown -R $SERVICE_USER.$SERVICE_GROUP $SERVICE_DIR
# Parameters.
DATE="`date +%Y%m%d`"
+HOST="$1"
+SERVICE="svn"
+SERVICE_DIR="/var/svn"
+SERVICE_USER="svn"
+SERVICE_GROUP="svn"
-# Check restore strategy.
-if [ "$1" == "localhost" ] || [ "$1" == "`facter hostname`" ]; then
- hydra_backup_environment_local
-else
- hydra_backup_environment_remote $1 restore
-fi
-
-# Check if folder exist on the backup.
-if [ -d "$RESTOREDIR/var/svn" ]; then
- echo "SVN folder does not exist: $RESTOREDIR/var/svn"
- exit 1
-fi
+# Set restore environment.
+hydra_backup_environment_service
# Backup it.
+# TODO: directly at hydra_backup_environment_service
hydractl backup-site svn
-# Set svn user.
-if hydra_check_user svn; then
- SVN_USER="svn"
-else
- SVN_USER="root"
-fi
-
-# Set svn group.
-if hydra_check_group svn; then
- SVN_GROUP="svn"
-else
- SVN_GROUP="root"
-fi
-
# Copy site folder from backup.
cp -a $RESTOREDIR/var/svn /var/svn
# Fix permissions.
chown root.root /var/svn
-chown -R $SVN_USER.$SVN_GROUP /var/svn/*
+chown -R $SERVICE_USER.$SERVICE_GROUP /var/svn/*
+
# Parameters.
DATE="`date +%Y%m%d`"
-LISTS_DIR="/var/mail/virtual"
+HOST="$1"
+SERVICE="sympa"
+SERVICE_DIR="/var/lib/sympa"
+SERVICE_USER="sympa"
+SERVICE_GROUP="sympa"
-# Check restore strategy.
-if [ "$1" == "localhost" ] || [ "$1" == "`facter hostname`" ]; then
- hydra_backup_environment_local
-else
- hydra_backup_environment_remote $1 restore
-fi
-
-# Check if folder exist on the backup.
-if [ ! -d "$RESTOREDIR/$LISTS_DIR" ]; then
- echo "Lists folder does not exist: $RESTOREDIR/$LISTS_DIR"
- exit 1
-fi
-
-# Set git user.
-if hydra_check_user sympa; then
- LISTS_USER="sympa"
-else
- LISTS_USER="root"
-fi
-
-# Set git group.
-if hydra_check_group sympa; then
- LISTS_GROUP="sympa"
-else
- LISTS_GROUP="root"
-fi
-
-# TODO: Backup it?
-#hydractl backup-sympa
+# Set restore environment.
+hydra_backup_environment_service
# Restore lists folders from backup.
-#rsync -av $RESTOREDIR/$LISTS_DIR/wwsarchive/ $LISTS_DIR/wwsarchive/
-#rsync -av $RESTOREDIR/$LISTS_DIR/expl/ $LISTS_DIR/expl/
-#rsync -av $RESTOREDIR/$LISTS_DIR/bounce/ $LISTS_DIR/bounce/
-rsync -av --delete $RESTOREDIR/$LISTS_DIR/ $LISTS_DIR/
+#rsync -av $RESTOREDIR/$SERVICE_DIR/wwsarchive/ $SERVICE_DIR/wwsarchive/
+#rsync -av $RESTOREDIR/$SERVICE_DIR/expl/ $SERVICE_DIR/expl/
+#rsync -av $RESTOREDIR/$SERVICE_DIR/bounce/ $SERVICE_DIR/bounce/
+rsync -av --delete $RESTOREDIR/$SERVICE_DIR/ $SERVICE_DIR/
# Restore database
hydra_backup_restore_database sympa
# Fix permissions.
-chown -R $LISTS_USER.$LISTS_GROUP $LISTS_DIR
+chown -R $SERVICE_USER.$SERVICE_GROUP $SERVICE_DIR