Skip to content

Commit

Permalink
update backup tool for synthia v4
Browse files Browse the repository at this point in the history
  • Loading branch information
nordurljosahvida committed Jun 12, 2021
1 parent 6ae8904 commit 7b9835c
Showing 1 changed file with 73 additions and 130 deletions.
203 changes: 73 additions & 130 deletions tools/raptor-backup
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
#!/usr/bin/env bash

################################################################################
### ############################################################################

### Set bash environment error management
### initialize script with standard synthia bootstrapping block.

### ############################################################################

#### 1 | add padding to output / clear screen.

echo

#### 2 | locate execution environment and perform synthia-bound operations.

#### ###########################################################################

##### set bash environment error management.

set -eu

################################################################################
##### determine script execution directory and install directory.

### Add padding to output
if [ -L "${BASH_SOURCE}" ]
then

echo
###### this file is being executed via a symlink.
###### therefore identify the parent directory of the target file.

################################################################################
link_target="$(readlink ${BASH_SOURCE})"
exec_dir="${link_target%/*}"

### Determine script execution directory and install directory.
else

###### this file is being directly executed.
###### therefore identify our parent directory.

exec_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
exec_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

fi

exec_dir_trim_2="$( echo ${exec_dir} | cut -f 1,2,3 -d'/')"
exec_dir_trim_3="$( echo ${exec_dir} | cut -f 1,2,3,4 -d'/')"
Expand All @@ -37,168 +57,91 @@ else
fi
fi

### Source local functions file.
##### source local functions file.

. "$exec_dir_root/functions"

################################################################################

### Define formatting
##### define formatting.

synthia-define_formatting

################################################################################

### Check for root user runtime
##### check for root user runtime.

synthia-check_root

################################################################################
#### ###########################################################################

### Source dna
#### 3 | source dna and perform dna-bound operations.

synthia-source_dna
#### ###########################################################################

################################################################################
##### source dna.

### Define variables
synthia-source_dna

synthia-define_vars
##### define variables.

################################################################################
synthia-define_vars

### Read conf settings
##### read conf settings.

dna-read_conf_settings

################################################################################
##### touch temp dir.

### Log script
dna-touch_tmp_project_dir

dna-log_script
#### ###########################################################################

################################################################################
#### 4 | head/log script.

while getopts ":s" arguments; do
case $arguments in
s) skip_install_complete_check="-s"
;;
\?) dna-echo -e "Invalid option | ${n-}-$OPTARG${r-} | for function | ${n-}${FUNCNAME[0]}${r-} |."
dna-exit
;;
esac
done
OPTIND=1

################################################################################
dna-log_script

### Check for lockfile to avoid multiple simultaneous backups
### ############################################################################

if [ -f /tmp/${project_name}-backup-running-lockfile ]
then
### evaluate arguments.

dna-echo -e "It appears a ${project_name} backup is already running, perhaps an automated daily one, or perhaps the last one was interrupted."
dna-echo -m "If this *is* an automated daily one, please check that you're not running a manual one or that the last run was interrupted."
dna-echo -m "Running multiple simultaneous backups is absolutely not supported and will make both fail."
### ############################################################################

if [ "${interactive}" = "y" ]
then
dna-ask_for_boolean -d "n" -q "If you're certain that another backup is NOT running, would you like to ignore the lockfile and continue?"
if [ "${boolean_output}" = "y" ]
then
dna-echo -m "Ok, continuing anyway..."
export lockfile_set="/tmp/${project_name}-backup-running-lockfile"
else
dna-echo -m "Ok, aborting..."
while getopts ":lsri" arguments
do
case $arguments in
l) export backup_locally_only="y"
;;
s) export backup_s3_only="y"
;;
r) export backup_last_before_restore="y"
;;
i) export backup_skip_install_complete_check="y"
;;
\?) dna-echo -e "Invalid option | ${n-}-${OPTARG}${r-} | for function | ${n-}${FUNCNAME[0]}${r-} |."
dna-exit
fi

else

dna-echo -m "If you're certain that another backup is NOT running, run this script manually and select to ignore the lockfile and continue when prompted."
dna-echo -m "Alternatively, you can also log into this machine and | ${o-}rm /tmp/${project_name}-backup-running-lockfile${n-} |."
dna-echo -e "Aborting backup for now."
dna-exit

fi

else

### Set lockfile.

export lockfile_set="/tmp/${project_name}-backup-running-lockfile"
touch "${lockfile_set}"

fi

################################################################################

dna-backup_purge_incomplete_archives

dna-backup_purge_dirs

dna-backup_create_dirs backup

dna-backup_update_storage_info

dna-backup_purge_backups

if [ "$backup_archival_location" = "s3" ]
then

dna-backup_restore_from_S3 test

dna-backup_purge_dirs

dna-backup_create_dirs backup

fi

dna-backup_locally "${skip_install_complete_check-}"

################################################################################
;;
esac
done
OPTIND=1

if [ "$backup_archival_location" = "s3" ]
if [ -n "${backup_last_before_restore-}" ]
then

if [ "${s3_restore_test_failed-null}" = "y" ]
if [ -n "${backup_s3_only-}" ]
then

dna-echo -e "Skipping S3 backup because of a previous test restore failure."

rm -r "$backup_tmp_dir"

else

mv "$backup_tmp_dir"/* "$backup_local_storage_path/latest"

############################################################################

dna-backup_to_S3
dna-echo -e "Option | ${n-}backup_s3_only [-s]${r-} | is incompatible with option | ${n-}backup_last_before_restore [-r]${r-} |."
dna-exit

fi

else

rm -r "$backup_tmp_dir"
export backup_locally_only="y"

fi

if [ -d "$backup_local_storage_path/temp" ]
then
rm -r "${backup_local_storage_path:?}/temp"
fi
### ############################################################################

dna-backup_purge_dirs
### actually start script operations.

if [ -f "/tmp/${project_name}-backup-running-lockfile" ]
then
rm "/tmp/${project_name}-backup-running-lockfile"
fi
### ############################################################################

if [ "${s3_restore_test_failed-null}" = "y" ]
then
dna-exit
fi
synthia-backup

dna-echo -s "Backup complete!"
### ############################################################################

0 comments on commit 7b9835c

Please sign in to comment.