Merge pull request #419 from github/enterprise-3.6-backport-348-users/boxofyellow/2023-06/mssql-backup_0
Backport 348 for 3.6: Allow the caller to handle setting failures
This commit is contained in:
Коммит
4d45408d37
|
@ -38,10 +38,10 @@ add_minute() {
|
|||
# Expect date string in the format of yyyymmddTHHMMSS
|
||||
# Here parse date differently depending on GNU Linux vs BSD MacOS
|
||||
if date -v -1d > /dev/null 2>&1; then
|
||||
echo "$(date -v +$2M -ujf'%Y%m%dT%H%M%S' $1 +%Y%m%dT%H%M%S)"
|
||||
date -v +"$2"M -ujf'%Y%m%dT%H%M%S' "$1" +%Y%m%dT%H%M%S
|
||||
else
|
||||
dt=$1
|
||||
echo "$(date -u '+%Y%m%dT%H%M%S' -d "${dt:0:8} ${dt:9:2}:${dt:11:2}:${dt:13:2} $2 minutes")"
|
||||
date -u '+%Y%m%dT%H%M%S' -d "${dt:0:8} ${dt:9:2}:${dt:11:2}:${dt:13:2} $2 minutes"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ find_timestamp() {
|
|||
filename="${1##*/}"
|
||||
IFS='@' read -ra parts <<< "$filename"
|
||||
datetime_part=${parts[1]:0:15}
|
||||
echo $datetime_part
|
||||
echo "$datetime_part"
|
||||
}
|
||||
|
||||
actions_dbs() {
|
||||
|
@ -98,7 +98,7 @@ get_latest_backup_file() {
|
|||
db=$2
|
||||
ext=$3
|
||||
|
||||
latest_full_backup=$(find "$backups_dir" -type f -name "$db*.$ext" | egrep '[0-9]{8}T[0-9]{6}' | sort | tail -n 1)
|
||||
latest_full_backup=$(find "$backups_dir" -type f -name "$db*.$ext" | grep -E '[0-9]{8}T[0-9]{6}' | sort | tail -n 1)
|
||||
latest_full_backup_file="${latest_full_backup##*/}"
|
||||
echo "$latest_full_backup_file"
|
||||
}
|
||||
|
@ -146,8 +146,8 @@ get_next_diff_backup_base_lsn() {
|
|||
|
||||
last_mssql=$GHE_DATA_DIR/current/mssql
|
||||
|
||||
if [ ! -d $last_mssql ] \
|
||||
|| [ -z "$(find $last_mssql -type f -name '*.bak' | head -n 1)" ]; then
|
||||
if [ ! -d "$last_mssql" ] \
|
||||
|| [ -z "$(find "$last_mssql" -type f -name '*.bak' | head -n 1)" ]; then
|
||||
ghe_verbose "Taking first full backup"
|
||||
backup_type="full"
|
||||
else
|
||||
|
@ -159,34 +159,34 @@ else
|
|||
current=$(date -u +%Y%m%d%H%M%S)
|
||||
|
||||
full=$(find "$last_mssql" -type f -name "*.bak" | head -n 1)
|
||||
full=$(find_timestamp $full)
|
||||
full_expire=$(add_minute $full ${cadence[0]})
|
||||
full=$(find_timestamp "$full")
|
||||
full_expire=$(add_minute "$full" "${cadence[0]}")
|
||||
full_expire="${full_expire//T}"
|
||||
|
||||
diff=$(find "$last_mssql" -type f -name "*.diff" | head -n 1)
|
||||
if [ -f "$diff" ]; then
|
||||
diff=$(find_timestamp $diff)
|
||||
diff_expire=$(add_minute $diff ${cadence[1]})
|
||||
diff=$(find_timestamp "$diff")
|
||||
diff_expire=$(add_minute "$diff" "${cadence[1]}")
|
||||
diff_expire="${diff_expire//T}"
|
||||
else
|
||||
diff_expire=$(add_minute $full ${cadence[1]})
|
||||
diff_expire=$(add_minute "$full" "${cadence[1]}")
|
||||
diff_expire="${diff_expire//T}"
|
||||
fi
|
||||
|
||||
tran=$(find "$last_mssql" -type f -name "*.log" | egrep '[0-9]{8}T[0-9]{6}' | sort | tail -1)
|
||||
tran=$(find_timestamp $tran)
|
||||
tran_expire=$(add_minute $tran ${cadence[2]})
|
||||
tran=$(find "$last_mssql" -type f -name "*.log" | grep -E '[0-9]{8}T[0-9]{6}' | sort | tail -1)
|
||||
tran=$(find_timestamp "$tran")
|
||||
tran_expire=$(add_minute "$tran" "${cadence[2]}")
|
||||
tran_expire="${tran_expire//T}"
|
||||
|
||||
ghe_verbose "current $current, full expire $full_expire, \
|
||||
diff expire $diff_expire, tran expire $tran_expire"
|
||||
|
||||
# Determine the type of backup to take based on expiry time
|
||||
if [ $current -gt $full_expire ]; then
|
||||
if [ "$current" -gt "$full_expire" ]; then
|
||||
backup_type='full'
|
||||
elif [ $current -gt $diff_expire ]; then
|
||||
elif [ "$current" -gt "$diff_expire" ]; then
|
||||
backup_type='diff'
|
||||
elif [ $current -gt $tran_expire ]; then
|
||||
elif [ "$current" -gt "$tran_expire" ]; then
|
||||
backup_type='transaction'
|
||||
fi
|
||||
|
||||
|
@ -264,8 +264,8 @@ fi
|
|||
mkdir -p "$backup_dir"
|
||||
|
||||
# Use hard links to "copy" over previous applicable backups to the new snapshot folder to save disk space and time
|
||||
if [ -d $last_mssql ]; then
|
||||
for p in $last_mssql/*
|
||||
if [ -d "$last_mssql" ]; then
|
||||
for p in "$last_mssql"/*
|
||||
do
|
||||
[[ -e "$p" ]] || break
|
||||
|
||||
|
@ -274,23 +274,23 @@ if [ -d $last_mssql ]; then
|
|||
transfer=
|
||||
|
||||
# Copy full backups unless we're taking a new full backup
|
||||
if [ $extension = "bak" ] && [ "$backup_type" != 'full' ]; then
|
||||
if [ "$extension" = "bak" ] && [ "$backup_type" != 'full' ]; then
|
||||
transfer=1
|
||||
fi
|
||||
|
||||
# Copy diff backups unless we're taking a new full or diff backup
|
||||
if [ $extension = "diff" ] && [ "$backup_type" != 'full' ] && [ "$backup_type" != 'diff' ]; then
|
||||
if [ "$extension" = "diff" ] && [ "$backup_type" != 'full' ] && [ "$backup_type" != 'diff' ]; then
|
||||
transfer=1
|
||||
fi
|
||||
|
||||
# Copy transaction log backups unless we're taking a new full or diff backup
|
||||
if [ $extension = "log" ] && [ "$backup_type" != 'full' ] && [ "$backup_type" != 'diff' ]; then
|
||||
if [ "$extension" = "log" ] && [ "$backup_type" != 'full' ] && [ "$backup_type" != 'diff' ]; then
|
||||
transfer=1
|
||||
fi
|
||||
|
||||
if [ -n "$transfer" ]; then
|
||||
ghe_verbose "Creating hard link to $filename"
|
||||
ln $last_mssql/$filename $backup_dir/$filename
|
||||
ln "$last_mssql"/"$filename" "$backup_dir"/"$filename"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
@ -305,9 +305,9 @@ if [ -n "$backup_type" ]; then
|
|||
backup_command='ghe-export-mssql -t'
|
||||
fi
|
||||
|
||||
bm_start "$(basename $0)"
|
||||
ghe-ssh "$GHE_HOSTNAME" -- "$backup_command" || failures="$failures mssql"
|
||||
bm_end "$(basename $0)"
|
||||
bm_start "$(basename "$0")"
|
||||
ghe-ssh "$GHE_HOSTNAME" -- "$backup_command"
|
||||
bm_end "$(basename "$0")"
|
||||
|
||||
# Configure the backup cadence on the appliance, which is used for diagnostics
|
||||
ghe-ssh "$GHE_HOSTNAME" "ghe-config mssql.backup.cadence $GHE_MSSQL_BACKUP_CADENCE"
|
||||
|
@ -319,6 +319,6 @@ if [ -n "$backup_type" ]; then
|
|||
for b in $backups
|
||||
do
|
||||
ghe_verbose "Transferring to backup host $b"
|
||||
ghe-ssh "$GHE_HOSTNAME" "sudo cat $appliance_dir/$b" > $backup_dir/$b
|
||||
ghe-ssh "$GHE_HOSTNAME" "sudo cat $appliance_dir/$b" > "$backup_dir"/"$b"
|
||||
done
|
||||
fi
|
||||
|
|
Загрузка…
Ссылка в новой задаче