mirror of
https://gh.wpcy.net/https://github.com/CaptainCore/captaincore.git
synced 2026-04-23 01:50:05 +08:00
54 lines
No EOL
1.4 KiB
Bash
54 lines
No EOL
1.4 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
#
|
|
# Fetches backups for a site
|
|
#
|
|
# `captaincore site backup get <site> <backup-id>`
|
|
#
|
|
|
|
while read config; do
|
|
if [[ "$config" == "Error:"* ]]; then
|
|
continue
|
|
fi
|
|
declare "$config"
|
|
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
|
|
|
|
if [ ${#@} -ne 2 ]; then
|
|
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify <site> and <backup-id>."
|
|
exit
|
|
fi
|
|
|
|
site=$1
|
|
backup_id=$2
|
|
|
|
# Extract environment
|
|
if [[ "$site" == *"-staging"* ]]; then
|
|
environment=staging
|
|
fi
|
|
|
|
if [[ "$site" == *"-production"* ]]; then
|
|
environment=production
|
|
fi
|
|
|
|
if [[ "$site" != *"-"* ]]; then
|
|
environment=production
|
|
fi
|
|
|
|
# Load site configs
|
|
IFS=$'\n'$'\r'; for line in $(captaincore site get $site --bash --captain-id=$CAPTAIN_ID); do declare "$line"; done
|
|
|
|
backup_files_link="$rclone_upload_uri/${site}_${site_id}/${environment}/backups/snapshot-$backup_id.json"
|
|
http_status=$( curl --write-out "%{http_code}" -o /dev/null -sI $backup_files_link )
|
|
|
|
if [[ "$http_status" != "200" ]]; then
|
|
# Attempt to generate missing backup files
|
|
silent=$( captaincore backup get-generate $site-$environment $backup_id --captain-id=$CAPTAIN_ID )
|
|
|
|
# check if backup file exists
|
|
http_status=$( curl --write-out "%{http_code}" -o /dev/null -sI $backup_files_link )
|
|
if [[ "$http_status" != "200" ]]; then
|
|
exit
|
|
fi
|
|
fi
|
|
|
|
echo $backup_files_link |