mirror of
https://ghproxy.net/https://github.com/CaptainCore/captaincore.git
synced 2026-07-28 13:07:02 +08:00
49 lines
No EOL
1.1 KiB
Bash
Executable file
49 lines
No EOL
1.1 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
#
|
|
# Fetches list of snapshots for a site from a backup repo
|
|
#
|
|
# `captaincore backup list <site>`
|
|
#
|
|
|
|
if [ ${#@} -eq 0 ]; then
|
|
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Requires a <site>"
|
|
exit
|
|
fi
|
|
|
|
while read config; do
|
|
if [[ "$config" == "Error:"* ]]; then
|
|
continue
|
|
fi
|
|
declare "$config"
|
|
done <<< "$(captaincore config fetch --captain-id=$CAPTAIN_ID)"
|
|
|
|
site=$1
|
|
|
|
run_command() {
|
|
|
|
# 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; unset IFS
|
|
|
|
backup_list="$path/${site}_${site_id}/${environment}/backups/list.json"
|
|
if [ ! -f "$backup_list" ] || [[ $( stat -c%s "$backup_list" 2>/dev/null || stat -f%z "$backup_list" 2>/dev/null ) == "0" ]]; then
|
|
captaincore backup list-generate $site-$environment --captain-id=$CAPTAIN_ID
|
|
fi
|
|
cat "$backup_list"
|
|
|
|
}
|
|
|
|
run_command |