#!/bin/bash
# info: backup all users
# options: NONE
#
# The function backups all system users.


#----------------------------------------------------------#
#                    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


#----------------------------------------------------------#
#                       Action                             #
#----------------------------------------------------------#

$BIN/v-check-vesta-license >/dev/null

if [ -z "$BACKUP_SYSTEM" ]; then
    exit
fi
for user in $(grep '@' /etc/passwd |cut -f1 -d:); do
    if [ ! -f "$VESTA/data/users/$user/user.conf" ]; then
        continue;
    fi
    check_suspend=$(grep "SUSPENDED='no'" $VESTA/data/users/$user/user.conf)
    log=$VESTA/log/backup.log
    if [ ! -z "$check_suspend" ]; then
        echo -e "================================" >> $log
        echo -e "$user" >> $log
        echo -e "--------------------------------\n" >> $log
        $BIN/v-backup-user $user >> $log 2>&1
        echo -e "\n--------------------------------\n\n" >> $log
    fi
done

#----------------------------------------------------------#
#                       Vesta                              #
#----------------------------------------------------------#

# No Logging
#log_event "$OK" "$ARGUMENTS"

exit