diff options
-rw-r--r-- | lib/hydra/backup | 33 | ||||
-rwxr-xr-x | share/hydractl/backup-restore-email | 49 | ||||
-rwxr-xr-x | share/hydractl/backup-restore-firma | 41 | ||||
-rwxr-xr-x | share/hydractl/backup-restore-gitosis | 39 | ||||
-rwxr-xr-x | share/hydractl/backup-restore-mlmmj | 41 | ||||
-rwxr-xr-x | share/hydractl/backup-restore-schleuder | 41 | ||||
-rwxr-xr-x | share/hydractl/backup-restore-svn | 37 | ||||
-rwxr-xr-x | share/hydractl/backup-restore-sympa | 47 |
8 files changed, 105 insertions, 223 deletions
diff --git a/lib/hydra/backup b/lib/hydra/backup index 0209570..9ac6833 100644 --- a/lib/hydra/backup +++ b/lib/hydra/backup @@ -88,6 +88,39 @@ function hydra_backup_environment_remote { 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" diff --git a/share/hydractl/backup-restore-email b/share/hydractl/backup-restore-email index f0d7979..d8d0d0c 100755 --- a/share/hydractl/backup-restore-email +++ b/share/hydractl/backup-restore-email @@ -22,51 +22,28 @@ hydra_config_load # 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 diff --git a/share/hydractl/backup-restore-firma b/share/hydractl/backup-restore-firma index eaed413..a6e62e0 100755 --- a/share/hydractl/backup-restore-firma +++ b/share/hydractl/backup-restore-firma @@ -22,41 +22,18 @@ hydra_config_load # 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 diff --git a/share/hydractl/backup-restore-gitosis b/share/hydractl/backup-restore-gitosis index a10b95f..928f357 100755 --- a/share/hydractl/backup-restore-gitosis +++ b/share/hydractl/backup-restore-gitosis @@ -21,40 +21,21 @@ source $APP_BASE/lib/hydra/functions || exit 1 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 diff --git a/share/hydractl/backup-restore-mlmmj b/share/hydractl/backup-restore-mlmmj index 6895a11..b175c32 100755 --- a/share/hydractl/backup-restore-mlmmj +++ b/share/hydractl/backup-restore-mlmmj @@ -22,41 +22,18 @@ hydra_config_load # 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 diff --git a/share/hydractl/backup-restore-schleuder b/share/hydractl/backup-restore-schleuder index eb744d5..c5885f8 100755 --- a/share/hydractl/backup-restore-schleuder +++ b/share/hydractl/backup-restore-schleuder @@ -22,43 +22,20 @@ hydra_config_load # 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 diff --git a/share/hydractl/backup-restore-svn b/share/hydractl/backup-restore-svn index 1425fdf..a4c90a5 100755 --- a/share/hydractl/backup-restore-svn +++ b/share/hydractl/backup-restore-svn @@ -22,40 +22,23 @@ hydra_config_load # 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/* + diff --git a/share/hydractl/backup-restore-sympa b/share/hydractl/backup-restore-sympa index ff1db6d..3bcdff4 100755 --- a/share/hydractl/backup-restore-sympa +++ b/share/hydractl/backup-restore-sympa @@ -22,47 +22,24 @@ hydra_config_load # 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 |