|
@@ -9,38 +9,43 @@ local commandaction="Backup"
|
|
|
local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
|
|
local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
|
|
|
|
|
|
|
|
check.sh
|
|
check.sh
|
|
|
|
|
+fn_print_header
|
|
|
# Check if a backup is pending or has been aborted using .backup.lock
|
|
# Check if a backup is pending or has been aborted using .backup.lock
|
|
|
if [ -f "${tmpdir}/.backup.lock" ]; then
|
|
if [ -f "${tmpdir}/.backup.lock" ]; then
|
|
|
- fn_print_warning_nl "A backup is currently pending or has been aborted."
|
|
|
|
|
|
|
+ fn_print_warning_nl "A backup is currently running or has been aborted."
|
|
|
|
|
+ fn_script_log_warn "A backup is currently running or has been aborted."
|
|
|
while true; do
|
|
while true; do
|
|
|
read -e -i "y" -p "Continue anyway? [Y/N]" yn
|
|
read -e -i "y" -p "Continue anyway? [Y/N]" yn
|
|
|
case $yn in
|
|
case $yn in
|
|
|
- [Yy]* ) break;;
|
|
|
|
|
- [Nn]* ) echo Exiting; return;;
|
|
|
|
|
|
|
+ [Yy]* ) fn_script_log "User continues anyway"; break;;
|
|
|
|
|
+ [Nn]* ) echo Exiting; fn_script_log "User aborted"; return;;
|
|
|
* ) echo "Please answer yes or no.";;
|
|
* ) echo "Please answer yes or no.";;
|
|
|
esac
|
|
esac
|
|
|
done
|
|
done
|
|
|
fi
|
|
fi
|
|
|
-info_distro.sh
|
|
|
|
|
fn_print_dots ""
|
|
fn_print_dots ""
|
|
|
sleep 0.5
|
|
sleep 0.5
|
|
|
# Prepare backup file name with servicename current date
|
|
# Prepare backup file name with servicename current date
|
|
|
backupname="${servicename}-$(date '+%Y-%m-%d-%H%M%S')"
|
|
backupname="${servicename}-$(date '+%Y-%m-%d-%H%M%S')"
|
|
|
-# Tells how much will be compressed using rootdirduexbackup value from info_distro
|
|
|
|
|
|
|
+# Tells how much will be compressed using rootdirduexbackup value from info_distro and prompt for continue
|
|
|
|
|
+info_distro.sh
|
|
|
fn_print_info_nl "A total of ${rootdirduexbackup} will be compressed into the following backup:"
|
|
fn_print_info_nl "A total of ${rootdirduexbackup} will be compressed into the following backup:"
|
|
|
echo "${backupdir}/${backupname}.tar.gz"
|
|
echo "${backupdir}/${backupname}.tar.gz"
|
|
|
while true; do
|
|
while true; do
|
|
|
read -e -i "y" -p "Continue? [Y/N]" yn
|
|
read -e -i "y" -p "Continue? [Y/N]" yn
|
|
|
case $yn in
|
|
case $yn in
|
|
|
[Yy]* ) break;;
|
|
[Yy]* ) break;;
|
|
|
- [Nn]* ) echo Exiting; return;;
|
|
|
|
|
|
|
+ [Nn]* ) echo "Exiting"; fn_script_log "User aborted"; return;;
|
|
|
* ) echo "Please answer yes or no.";;
|
|
* ) echo "Please answer yes or no.";;
|
|
|
esac
|
|
esac
|
|
|
done
|
|
done
|
|
|
|
|
+
|
|
|
|
|
+# Check if server is started
|
|
|
check_status.sh
|
|
check_status.sh
|
|
|
if [ "${status}" != "0" ]; then
|
|
if [ "${status}" != "0" ]; then
|
|
|
echo ""
|
|
echo ""
|
|
|
fn_print_warning_nl "${servicename} is currently running."
|
|
fn_print_warning_nl "${servicename} is currently running."
|
|
|
|
|
+
|
|
|
sleep 1
|
|
sleep 1
|
|
|
while true; do
|
|
while true; do
|
|
|
read -p "Stop ${servicename} while running the backup? [Y/N]" yn
|
|
read -p "Stop ${servicename} while running the backup? [Y/N]" yn
|
|
@@ -60,12 +65,16 @@ if [ ! -d "${backupdir}" ]; then
|
|
|
fi
|
|
fi
|
|
|
# Create lockfile
|
|
# Create lockfile
|
|
|
touch "${tmpdir}/.backup.lock"
|
|
touch "${tmpdir}/.backup.lock"
|
|
|
|
|
+fn_script_log "Lockfile created"
|
|
|
# Compressing files
|
|
# Compressing files
|
|
|
|
|
+fn_script_log "Compressing ${rootdirduexbackup}".
|
|
|
tar -czf "${backupdir}/${backupname}.tar.gz" -C "${rootdir}" --exclude "backups" ./*
|
|
tar -czf "${backupdir}/${backupname}.tar.gz" -C "${rootdir}" --exclude "backups" ./*
|
|
|
# Remove lockfile
|
|
# Remove lockfile
|
|
|
rm "${tmpdir}/.backup.lock"
|
|
rm "${tmpdir}/.backup.lock"
|
|
|
|
|
+fn_script_log "Lockfile removed"
|
|
|
# Check tar exit code and act accordingly
|
|
# Check tar exit code and act accordingly
|
|
|
if [ $? == 0 ]; then
|
|
if [ $? == 0 ]; then
|
|
|
|
|
+ # Exit code doesn't report any error
|
|
|
fn_print_ok_nl "Backup created: ${backupname}.tar.gz is $(du -sh "${backupdir}/${backupname}.tar.gz" | awk '{print $1}') size"
|
|
fn_print_ok_nl "Backup created: ${backupname}.tar.gz is $(du -sh "${backupdir}/${backupname}.tar.gz" | awk '{print $1}') size"
|
|
|
fn_script_log_pass "Backup created: ${backupdir}/${backupname}.tar.gz is $(du -sh "${backupdir}/${backupname}.tar.gz" | awk '{print $1}') size"
|
|
fn_script_log_pass "Backup created: ${backupdir}/${backupname}.tar.gz is $(du -sh "${backupdir}/${backupname}.tar.gz" | awk '{print $1}') size"
|
|
|
|
|
|
|
@@ -76,11 +85,12 @@ if [ $? == 0 ]; then
|
|
|
# Check if there is any backup to clear
|
|
# Check if there is any backup to clear
|
|
|
if [ "${backupclearcount}" -ne "0" ]; then
|
|
if [ "${backupclearcount}" -ne "0" ]; then
|
|
|
fn_print_info_nl "${backupclearcount} backups older than ${backupdays} days can be cleared."
|
|
fn_print_info_nl "${backupclearcount} backups older than ${backupdays} days can be cleared."
|
|
|
|
|
+ fn_script_log "${backupclearcount} backups older than ${backupdays} days can be cleared."
|
|
|
while true; do
|
|
while true; do
|
|
|
read -p "Clear older backups? [Y/N]" yn
|
|
read -p "Clear older backups? [Y/N]" yn
|
|
|
case $yn in
|
|
case $yn in
|
|
|
[Yy]* ) clearoldbackups="yes"; break;;
|
|
[Yy]* ) clearoldbackups="yes"; break;;
|
|
|
- [Nn]* ) clearoldbackups="no"; break;;
|
|
|
|
|
|
|
+ [Nn]* ) clearoldbackups="no"; fn_script_log "User didn't clear backups"; break;;
|
|
|
* ) echo "Please answer yes or no.";;
|
|
* ) echo "Please answer yes or no.";;
|
|
|
esac
|
|
esac
|
|
|
done
|
|
done
|
|
@@ -96,6 +106,7 @@ if [ $? == 0 ]; then
|
|
|
command_start.sh
|
|
command_start.sh
|
|
|
fi
|
|
fi
|
|
|
else
|
|
else
|
|
|
|
|
+ # Exit code reports an error
|
|
|
fn_print_error_nl "Backup failed: ${backupname}.tar.gz"
|
|
fn_print_error_nl "Backup failed: ${backupname}.tar.gz"
|
|
|
fn_script_log_error "Backup failed: ${backupname}.tar.gz"
|
|
fn_script_log_error "Backup failed: ${backupname}.tar.gz"
|
|
|
fi
|
|
fi
|