myvesta/bin/v-backup-users
myvesta 7e209c543d
Update v-backup-users
Prevent removing valid licenses when vestacp.com is offline.
Licences are free now - https://forum.myvestacp.com/viewtopic.php?t=949
2024-02-27 13:05:59 +01:00

93 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
# info: backup all users
# options: NONE
#
# The function backups all system users.
scriptname="v-backup-users"
for pid in $(pidof -x "$scriptname"); do
if [ $pid != $$ ]; then
echo "[$(date)] : $scriptname : Process is already running with PID $pid"
exit 1
fi
done
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Importing system environment as we run this script
# mostly by cron which not read it by itself
source /etc/profile
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
ALLOW_MYSQL_REPAIR=1
if [ $# -ge 1 ]; then
ALLOW_MYSQL_REPAIR=$1
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
log=$VESTA/log/backup.log
# $BIN/v-check-vesta-license >/dev/null
touch $log
if [ ! -z "$NOTIFY_ADMIN_FULL_BACKUP" ]; then
mv $log $log-`date +"%Y-%m-%d--%H:%M:%S"`
fi
# Auto-repair all databases before backuping all accounts
if [ $ALLOW_MYSQL_REPAIR -eq 1 ]; then
nice -n 19 ionice -c 3 mysqlrepair --all-databases --check --auto-repair >> $log 2>&1
fi
if [ -z "$BACKUP_SYSTEM" ]; then
exit
fi
FINAL_STATUS='OK'
i_am_in_backup_all_users=1
for user in $(grep '@' /etc/passwd |cut -f1 -d:); do
if [ ! -f "$VESTA/data/users/$user/user.conf" ]; then
continue;
fi
wait_for_backup_if_it_is_not_time_for_backup
check_suspend=$(grep "SUSPENDED='no'" $VESTA/data/users/$user/user.conf)
if [ ! -z "$check_suspend" ]; then
echo -e "================================" >> $log
echo -e "$user" >> $log
echo -e "--------------------------------\n" >> $log
i_am_in_backup_all_users=0
nice -n 19 ionice -c 3 $BIN/v-backup-user $user >> $log 2>&1
STATUS=$?
if [ $STATUS -ne 0 ]; then
FINAL_STATUS='CONTAINS ERRORS !!!'
fi
i_am_in_backup_all_users=1
echo -e "\n--------------------------------\n\n" >> $log
fi
done
if [ ! -z "$NOTIFY_ADMIN_FULL_BACKUP" ]; then
cat $log |$SENDMAIL -s "Full backup report for $HOSTNAME; status=$FINAL_STATUS" "$NOTIFY_ADMIN_FULL_BACKUP" 'yes'
fi
if [ ! -z "$NOTIFY_ADMIN_FULL_BACKUP2" ]; then
cat $log |$SENDMAIL -s "Full backup report for $HOSTNAME; status=$FINAL_STATUS" "$NOTIFY_ADMIN_FULL_BACKUP2" 'yes'
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# No Logging
#log_event "$OK" "$ARGUMENTS"
exit