2019-06-01 17:24:47 +02:00
print_config_title 'CHECK AUTO-BACKUP'
# Check if auto-backup script is present
2019-06-23 16:20:23 +02:00
echo "Check if auto-update script is present"
2019-06-01 17:24:47 +02:00
if [ [ -f " ${ BACKUP_SCRIPT } " ] ]
then
echo -e " ${ GREEN } The auto-backup script is present : check OK ${ NC } \n "
2019-06-29 11:26:10 +02:00
# Check the script (content)
echo "Check the script (content)"
grep -q 'borg prune -v backup@loth.grifon.fr' ${ BACKUP_SCRIPT }
RCa = ${ ? } # First Return Code
grep -q 'borg create --info .* backup@loth.grifon.fr:$(hostname -s)::$(date +%F)' ${ BACKUP_SCRIPT }
RCb = ${ ? } # Second Return Code
if [ [ ${ RCa } -ne 0 ] ] || [ [ ${ RCb } -ne 0 ] ]
then
AUTOBACKUP_CONFIG_CHECK_FAILED = ${ AUTOBACKUP_CONFIG_CHECK_FAILED } " Auto-backup script ${ BACKUP_SCRIPT } does NOT CONTAIN valid 'borg prune' OR 'borg create', check manually; "
echo -e " ${ RED } Auto-backup script does NOT CONTAIN valid 'borg prune' OR 'borg create' : check KO ${ NC } \n "
# Service started without error
else
echo -e " ${ GREEN } Auto-backup script seems contain valid 'borg prune' and 'borg create' : check OK ${ NC } \n "
fi
2019-06-01 17:24:47 +02:00
2019-06-29 11:26:10 +02:00
# Check if the script is executable
echo "Check if the script is executable"
if [ [ -x " ${ BACKUP_SCRIPT } " ] ]
then
echo -e " ${ GREEN } The auto-backup script is executable : check OK ${ NC } \n "
else
AUTOBACKUP_CONFIG_CHECK_FAILED = ${ AUTOBACKUP_CONFIG_CHECK_FAILED } " The auto-backup script is NOT executable;"
echo -e " ${ RED } The auto-backup script is NOT executable: check KO ${ NC } \n "
fi
2019-06-01 17:24:47 +02:00
2019-06-29 11:26:10 +02:00
# Check the ssh connection to the backup server
echo "Check the ssh connection to the backup server"
ssh -q ${ BACKUP_REMOTE_USER } @${ BACKUP_REMOTE_SERVER } exit
if [ [ ${ ? } -ne 0 ] ]
then
AUTOBACKUP_CONFIG_CHECK_FAILED = ${ AUTOBACKUP_CONFIG_CHECK_FAILED } " The SSH connection to the backup server failed, check manually;"
echo -e " ${ RED } SSH Connection to the backup server does NOT WORK : check KO ${ NC } \n "
# Service started without error
else
echo -e " ${ GREEN } SSH Connection to the backup server works : check OK ${ NC } \n "
fi
2019-06-01 17:24:47 +02:00
2019-06-29 11:26:10 +02:00
# Check if the remote repertory exist and is writable
echo "Check if the remote repertory exist and is writable"
ssh ${ BACKUP_REMOTE_USER } @${ BACKUP_REMOTE_SERVER } " test -w ${ BACKUP_REMOTE_REPERTORY } / $( hostname -s) " & >/dev/null
if [ [ ${ ? } -ne 0 ] ]
then
AUTOBACKUP_CONFIG_CHECK_FAILED = ${ AUTOBACKUP_CONFIG_CHECK_FAILED } " The remote backup repertory ${ BACKUP_REMOTE_REPERTORY } / $( hostname -s) does not exit, create it; "
echo -e " ${ RED } The remote backup repertory DOES NOT exit : check KO ${ NC } \n "
# Service started without error
else
echo -e " ${ GREEN } The remote backup repertory exist : check OK ${ NC } \n "
fi
2019-06-01 17:24:47 +02:00
2019-06-29 11:26:10 +02:00
# Check if the remote link exist and is writable : when a backup is done, the script set the destination : ~/$(hostname -s) which is a link to ${BACKUP_REMOTE_REPERTORY}/$(hostname -s)
echo "Check if the remote link exist and is writable"
ssh ${ BACKUP_REMOTE_USER } @${ BACKUP_REMOTE_SERVER } " test -w $( hostname -s) " & >/dev/null
if [ [ ${ ? } -ne 0 ] ]
then
AUTOBACKUP_CONFIG_CHECK_FAILED = ${ AUTOBACKUP_CONFIG_CHECK_FAILED } " The remote backup symbolic link ~/ $( hostname -s) does not exit, create it; "
echo -e " ${ RED } The remote backup symbolic link does not exist : check KO ${ NC } \n "
# Service started without error
else
echo -e " ${ GREEN } The remote backup symbolic link exist : check OK ${ NC } \n "
fi
2019-06-01 17:24:47 +02:00
2019-06-29 11:26:10 +02:00
# Check if the cron task is configured
echo "Check if the cron task is configured"
crontab -l 2>/dev/null | grep -q " ${ BACKUP_SCRIPT } "
RCa = ${ ? } # First Return Code
grep -q " ${ BACKUP_SCRIPT } " /etc/cron.d/*
RCb = ${ ? } # Second Return Code
grep -q " ${ BACKUP_SCRIPT } " /etc/crontab
RCc = ${ ? } # Third Return Code
if [ [ ${ RCa } -ne 0 ] ] && [ [ ${ RCb } -ne 0 ] ] && [ [ ${ RCc } -ne 0 ] ]
then
AUTOBACKUP_CONFIG_CHECK_FAILED = ${ AUTOBACKUP_CONFIG_CHECK_FAILED } " No cron entry for auto-backup, configure it;"
echo -e " ${ RED } NO cron entry for auto-backup : check KO ${ NC } \n "
# Service started without error
else
echo -e " ${ GREEN } Cron entry for auto-backup exist: check OK ${ NC } \n "
fi
2019-06-01 17:24:47 +02:00
else
2019-06-29 11:26:10 +02:00
AUTOBACKUP_CONFIG_CHECK_FAILED = ${ AUTOBACKUP_CONFIG_CHECK_FAILED } " The auto-backup script is NOT on the system;"
echo -e " ${ RED } The auto-backup is NOT on the system : check KO ${ NC } \n "
2019-06-01 17:24:47 +02:00
fi