commit f4e5d9dcbd0724f93fa0286e05e6f35ffc011dca Author: mattspeer Date: Sat Dec 20 12:08:11 2025 -0600 Upload files to "/" diff --git a/asg_website_backup.sh b/asg_website_backup.sh new file mode 100644 index 0000000..8afa6cf --- /dev/null +++ b/asg_website_backup.sh @@ -0,0 +1,112 @@ +#!/bin/bash + +# ============================================================================== +# SSH Backup and Download Script +# +# Description: +# This script connects to a remote server to perform a backup, then downloads +# the backup files to the local machine. It uses SSH keys for secure, +# password-less authentication. +# 1. Connects via SSH to the remote server. +# 2. Zips a specified directory on the remote server. +# 3. Exports a WordPress database on the remote server. +# 4. Downloads the zipped directory to the local ~/Downloads folder. +# 5. Downloads the SQL database backup to the local ~/Downloads folder. +# 6. Removes the created backup files from the remote server. +# +# Usage: +# ./connect.sh +# +# ============================================================================== + +# --- Configuration --- +# The username for the SSH connection. +USERNAME="mattspeer" + +# The hostname or IP address of the server to connect to. +HOSTNAME="addsourcegroup.com" + +# --- Main Execution --- + +echo "Connecting to ${HOSTNAME} to run backup commands..." + +# Define filenames that will be created on the remote server. +# This needs to be done locally to ensure the filenames match for removal. +DATE_STAMP=$(date +"%Y-%m-%d") +REMOTE_WEBSITE_BACKUP_FILENAME="addsourcegroup_com_${DATE_STAMP}.zip" +REMOTE_DB_BACKUP_FILENAME="db_backup_${DATE_STAMP}.sql" + +# Use a Here Document (Heredoc) to pass a block of commands to the remote server. +# Using 'EOF' in quotes prevents the local shell from expanding variables, +# ensuring that commands like `date` are executed on the remote server. +# No password or password variable is needed due to SSH key authentication. +ssh "${USERNAME}@${HOSTNAME}" <&2 + fi + + else + echo "An error occurred during the file download. Remote files were NOT removed." >&2 + exit 1 + fi + +else + echo "An error occurred during the remote execution. Halting script." >&2 + exit 1 +fi \ No newline at end of file