Add auto-backup check, WARN : not fully tested
This commit is contained in:
parent
1dbccd4f0a
commit
3346fb91bb
83
recipes/recipe_check_autobackup_config.sh
Normal file
83
recipes/recipe_check_autobackup_config.sh
Normal file
|
@ -0,0 +1,83 @@
|
|||
print_config_title 'CHECK AUTO-BACKUP'
|
||||
|
||||
# Check if auto-backup script is present
|
||||
if [[ -f "${BACKUP_SCRIPT}" ]]
|
||||
then
|
||||
echo -e "${GREEN}The auto-backup script is present : check OK${NC}\n"
|
||||
else
|
||||
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"
|
||||
fi
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
# 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
|
||||
|
||||
# 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
|
||||
|
||||
# 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)
|
||||
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
|
||||
|
||||
# Check if the cron task is configured
|
||||
crontab -l |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
|
Loading…
Reference in a new issue