More improvements and fixes
parent
1291e4a255
commit
c6aa1a191a
28
manifest.jps
28
manifest.jps
|
@ -148,7 +148,7 @@ actions:
|
||||||
configureAutoBackup:
|
configureAutoBackup:
|
||||||
- cmd[cp]:
|
- cmd[cp]:
|
||||||
user: root
|
user: root
|
||||||
commands: bash "/home/jelastic/mb-backups/manage_backup_schedule.sh" add "0 0 * * *" "$(cat /etc/restic-password)"
|
commands: bash "/home/jelastic/mb-backups/manage_backup_schedule.sh" add "0 0 * * *" "$(cat /etc/restic-password)" "${globals.envName}"
|
||||||
- return:
|
- return:
|
||||||
type: info
|
type: info
|
||||||
message: "Daily backup schedule configured successfully"
|
message: "Daily backup schedule configured successfully"
|
||||||
|
@ -156,55 +156,55 @@ actions:
|
||||||
removeAutoBackup:
|
removeAutoBackup:
|
||||||
- cmd[cp]:
|
- cmd[cp]:
|
||||||
user: root
|
user: root
|
||||||
commands: bash /home/litespeed/mb-backups/manage_backup_schedule.sh remove
|
commands: bash /home/litespeed/mb-backups/manage_backup_schedule.sh remove "${globals.envName}"
|
||||||
- return:
|
- return:
|
||||||
type: info
|
type: info
|
||||||
message: "${response.out}"
|
message: "${response.out}"
|
||||||
|
|
||||||
checkBackupRepo:
|
checkBackupRepo:
|
||||||
- cmd[cp]:
|
- cmd[cp]:
|
||||||
user: root
|
user: root
|
||||||
commands: bash /home/jelastic/mb-backups/backup-logic.sh check_backup_repo "${globals.envName}"
|
commands: bash /home/jelastic/mb-backups/backup-logic.sh check_backup_repo "${globals.envName}"
|
||||||
- return:
|
- return:
|
||||||
type: info
|
type: info
|
||||||
message: "${response.out}"
|
message: "${response.out}"
|
||||||
|
|
||||||
backupnow:
|
backupnow:
|
||||||
- cmd[cp]:
|
- cmd[cp]:
|
||||||
user: root
|
user: root
|
||||||
commands: bash /home/jelastic/mb-backups/backup-logic.sh "backup"
|
commands: bash /home/jelastic/mb-backups/backup-logic.sh "${globals.envName}" "backup"
|
||||||
- return:
|
- return:
|
||||||
type: info
|
type: info
|
||||||
message: "${response.out}"
|
message: "${response.out}"
|
||||||
|
|
||||||
backupcore:
|
backupcore:
|
||||||
- cmd[cp]:
|
- cmd[cp]:
|
||||||
user: root
|
user: root
|
||||||
commands: bash /home/jelastic/mb-backups/backup_core_files.sh "${globals.envName}" "${settings.blabel}"
|
commands: bash /home/jelastic/mb-backups/backup_core_files.sh "${globals.envName}" "${settings.blabel}"
|
||||||
- return:
|
- return:
|
||||||
type: info
|
type: info
|
||||||
message: "${response.out}"
|
message: "${response.out}"
|
||||||
|
|
||||||
backupmedia:
|
backupmedia:
|
||||||
- cmd[cp]:
|
- cmd[cp]:
|
||||||
user: root
|
user: root
|
||||||
commands: bash /home/jelastic/mb-backups/backup_media.sh "${globals.envName}" "${settings.blabel}"
|
commands: bash /home/jelastic/mb-backups/backup_media.sh "${globals.envName}" "${settings.blabel}"
|
||||||
- return:
|
- return:
|
||||||
type: info
|
type: info
|
||||||
message: "${response.out}"
|
message: "${response.out}"
|
||||||
|
|
||||||
backupdb:
|
backupdb:
|
||||||
- cmd[cp]:
|
- cmd[cp]:
|
||||||
user: root
|
user: root
|
||||||
commands: bash /home/jelastic/mb-backups/backup_database.sh "${globals.envName}" "${settings.blabel}"
|
commands: bash /home/jelastic/mb-backups/backup_database.sh "${globals.envName}" "${settings.blabel}"
|
||||||
- return:
|
- return:
|
||||||
type: info
|
type: info
|
||||||
message: "${response.out}"
|
message: "${response.out}"
|
||||||
|
|
||||||
restore:
|
restore:
|
||||||
- cmd[cp]:
|
- cmd[cp]:
|
||||||
user: root
|
user: root
|
||||||
commands: bash /home/jelastic/mb-backups/restore_backup_direct.sh "${settings.snapshotId}" "${globals.envName}"
|
commands: bash /home/jelastic/mb-backups/restore_backup_direct.sh "${settings.snapshotId}" "${globals.envName}"
|
||||||
- return:
|
- return:
|
||||||
type: info
|
type: info
|
||||||
message: "${response.out}"
|
message: "${response.out}"
|
||||||
|
|
|
@ -1,27 +1,30 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -e # Exit on error
|
set -e # Exit on error
|
||||||
trap 'echo "[$(date +'%Y-%m-%d %H:%M:%S')] ERROR: An error occurred. Exiting." | tee -a "$LOG_FILE"' ERR
|
trap 'log_message "ERROR: An error occurred. Exiting."' ERR
|
||||||
|
|
||||||
# Global Configurations
|
# Global Configurations
|
||||||
LOG_FILE="/var/log/backup_script.log"
|
LOG_FILE="/var/log/backup_script.log"
|
||||||
BACKUP_REPO_PATH="/mnt/backups/${ENV_NAME}"
|
|
||||||
PASSWORD_FILE="/etc/restic-password"
|
|
||||||
RESTIC_CONFIG_FILE="/etc/restic-config"
|
|
||||||
DEFAULT_BACKUP_COUNT=5
|
DEFAULT_BACKUP_COUNT=5
|
||||||
|
|
||||||
|
# Validate required variables
|
||||||
|
validate_inputs() {
|
||||||
|
: "${ENV_NAME:?ENV_NAME not set or empty. Please provide an environment name.}"
|
||||||
|
: "${RESTIC_PASSWORD:?RESTIC_PASSWORD not set}"
|
||||||
|
: "${APP_PATH:?APP_PATH not set}"
|
||||||
|
|
||||||
|
# Dynamically set the backup path
|
||||||
|
BACKUP_REPO_PATH="/mnt/backups/${ENV_NAME}"
|
||||||
|
[ -d "$BACKUP_REPO_PATH" ] || mkdir -p "$BACKUP_REPO_PATH"
|
||||||
|
export BACKUP_REPO_PATH
|
||||||
|
}
|
||||||
|
|
||||||
# Logging function
|
# Logging function
|
||||||
log_message() {
|
log_message() {
|
||||||
local message="$1"
|
local message="$1"
|
||||||
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $message" | tee -a "$LOG_FILE"
|
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $message" | tee -a "$LOG_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Validate required variables
|
|
||||||
validate_inputs() {
|
|
||||||
: "${RESTIC_PASSWORD:?RESTIC_PASSWORD not set}"
|
|
||||||
: "${BACKUP_REPO_PATH:?BACKUP_REPO_PATH not set}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Ensure Restic is installed
|
# Ensure Restic is installed
|
||||||
install_restic() {
|
install_restic() {
|
||||||
if ! which restic &>/dev/null; then
|
if ! which restic &>/dev/null; then
|
||||||
|
@ -40,8 +43,6 @@ install_restic() {
|
||||||
|
|
||||||
# Initialize or validate repository
|
# Initialize or validate repository
|
||||||
check_backup_repo() {
|
check_backup_repo() {
|
||||||
[ -d "$BACKUP_REPO_PATH" ] || mkdir -p "$BACKUP_REPO_PATH"
|
|
||||||
|
|
||||||
if ! restic -r "$BACKUP_REPO_PATH" snapshots &>/dev/null; then
|
if ! restic -r "$BACKUP_REPO_PATH" snapshots &>/dev/null; then
|
||||||
log_message "Initializing new Restic repository..."
|
log_message "Initializing new Restic repository..."
|
||||||
restic -r "$BACKUP_REPO_PATH" init
|
restic -r "$BACKUP_REPO_PATH" init
|
||||||
|
|
Loading…
Reference in New Issue