.
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 18s

This commit is contained in:
Your Name
2025-05-10 12:44:37 +12:00
parent b5bc7b611d
commit 9e9d80570c
3 changed files with 46 additions and 22 deletions

View File

@ -1,13 +1,9 @@
#!/bin/bash
# This script contains the common code for the autocommands.
_check_required_env_vars "BACKUP_FILE" "TEMP_DIR"
MYID=$(id -u)
MYGRP=$(id -g)
BACKUP_TEMP_PATH="$TEMP_DIR/backup"
_autocommandrun_volume() {
local command="$1"
local volume_name="$2"
@ -112,7 +108,8 @@ _autocommandparse() {
local command="$1"
shift
echo "autocommandparse: command=$command"
local backup_temp_path="$1"
shift
# Extract the backup file and temp path (last two arguments)
local args=("$@")
@ -132,7 +129,7 @@ _autocommandparse() {
# create backup folder unique to key/value.
local bfolder=$(echo "${key}_${value}" | tr -cd '[:alnum:]_-')
local targetpath="${BACKUP_TEMP_PATH}/${bfolder}"
local targetpath="${backup_temp_path}/${bfolder}"
mkdir -p ${targetpath}
# Key must be one of volume, path or file
@ -155,31 +152,57 @@ _autocommandparse() {
autocreate() {
_autocommandparse create "$@"
_check_required_env_vars "TEMP_DIR"
local create_temp_path="$TEMP_DIR/create"
mkdir -p "$create_temp_path"
_autocommandparse create "$create_temp_path" "$@"
rm -rf "$create_temp_path"
}
autonuke() {
_autocommandparse nuke "$@"
_check_required_env_vars "TEMP_DIR"
local nuke_temp_path="$TEMP_DIR/nuke"
mkdir -p "$nuke_temp_path"
_autocommandparse nuke "$nuke_temp_path" "$@"
rm -rf "$nuke_temp_path"
}
autobackup() {
mkdir -p "$BACKUP_TEMP_PATH"
echo "_autocommandparse [backup] [$@]"
_autocommandparse backup "$@"
_check_required_env_vars "BACKUP_FILE" "TEMP_DIR"
local backup_temp_path="$TEMP_DIR/backup"
tar zcvf "$BACKUP_FILE" -C "$BACKUP_TEMP_PATH" .
mkdir -p "$backup_temp_path"
echo "_autocommandparse [backup] [$backup_temp_path] [$@]"
# backup the files into the temp path.
_autocommandparse backup "$backup_temp_path" "$@"
# create the backup file.
tar zcvf "$BACKUP_FILE" -C "$backup_temp_path" .
rm -rf "$backup_temp_path"
}
autorestore() {
echo "_autocommandparse [restore] [$@]"
_check_required_env_vars "BACKUP_FILE" "TEMP_DIR"
local backup_temp_path="$TEMP_DIR/restore"
mkdir -p "$BACKUP_TEMP_PATH"
tar zxvf "$BACKUP_FILE" -C "$BACKUP_TEMP_PATH" --strip-components=1
echo "_autocommandparse [restore] [$backup_temp_path] [$@]"
_autocommandparse restore "$@"
mkdir -p "$backup_temp_path"
# extract the backup file into the temp path.
tar zxvf "$BACKUP_FILE" -C "$backup_temp_path" --strip-components=1
# restore the files from the temp path.
_autocommandparse restore "$backup_temp_path" "$@"
rm -rf "$backup_temp_path"
}