mirror of
https://github.com/lobomfz/VIctory-xmem.git
synced 2026-12-06 05:48:38 +00:00
update.sh: back up saves with one shared tool
The tool discovers local/data/*, writes to saves-backup/, keeps the newest 10 per data directory, and update.sh stops if the backup fails. No home-directory or title-ID assumptions.
This commit is contained in:
@ -41,7 +41,9 @@ The full tool and `pkg-config` lists are in [docs/BUILD.md](docs/BUILD.md).
|
||||
`setup.sh` fetches and builds Mesa, vkd3d-proton, a patched Wine server (unless
|
||||
Proton is used), the Windows SDK and VIctory itself. `./setup.sh fsr4` is the
|
||||
optional FSR 4 step. `build.sh` builds the Windows target; `update.sh` merges
|
||||
the latest `origin/main` and rebuilds.
|
||||
the latest `origin/main` and rebuilds. Before merging, it backs up the title's
|
||||
saves and settings to `saves-backup/` in this checkout, keeping the newest 10
|
||||
per data directory.
|
||||
|
||||
See [docs/BUILD.md](docs/BUILD.md) for versions, required packages and the
|
||||
single-step rebuild commands.
|
||||
|
||||
88
tools/backup-saves.sh
Executable file
88
tools/backup-saves.sh
Executable file
@ -0,0 +1,88 @@
|
||||
#!/bin/bash
|
||||
# Back up the title's saves and settings.
|
||||
# usage: tools/backup-saves.sh [--dest DIR] [--keep N] [--data DIR]
|
||||
set -euo pipefail
|
||||
umask 077
|
||||
|
||||
root=$(cd "$(dirname "$(readlink -f "$0")")/.." && pwd)
|
||||
dest=${SAVES_BACKUP_DIR:-$root/saves-backup}
|
||||
keep=${SAVES_BACKUP_KEEP:-10}
|
||||
data=${SAVES_DATA_DIR:-}
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
usage: tools/backup-saves.sh [--dest DIR] [--keep N] [--data DIR]
|
||||
|
||||
--dest DIR where the archives go (default: <checkout>/saves-backup)
|
||||
--keep N keep the newest N archives per data directory (default: 10; 0 keeps all)
|
||||
--data DIR one title data directory instead of local/data/*
|
||||
|
||||
The environment variables SAVES_BACKUP_DIR, SAVES_BACKUP_KEEP and
|
||||
SAVES_DATA_DIR set the same defaults.
|
||||
EOF
|
||||
}
|
||||
|
||||
while (( $# )); do
|
||||
case $1 in
|
||||
--dest) dest=${2:?--dest needs a directory}; shift 2;;
|
||||
--keep) keep=${2:?--keep needs a number}; shift 2;;
|
||||
--data) data=${2:?--data needs a directory}; shift 2;;
|
||||
-h|--help) usage; exit 0;;
|
||||
*) usage >&2; exit 2;;
|
||||
esac
|
||||
done
|
||||
|
||||
if ! [[ $keep =~ ^[0-9]+$ ]]; then
|
||||
echo "saves: --keep must be a number" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [ -n "$data" ]; then
|
||||
sources=("$data")
|
||||
where=$data
|
||||
else
|
||||
shopt -s nullglob
|
||||
sources=("$root"/local/data/*)
|
||||
shopt -u nullglob
|
||||
where=$root/local/data
|
||||
fi
|
||||
|
||||
found=0
|
||||
for src in "${sources[@]}"; do
|
||||
[ -d "$src" ] || continue
|
||||
files=()
|
||||
[ -d "$src/saves" ] && files+=(saves)
|
||||
[ -e "$src/storage/settings" ] && files+=(storage/settings)
|
||||
(( ${#files[@]} )) || continue
|
||||
|
||||
found=1
|
||||
id=$(basename "$src")
|
||||
id=${id//[^A-Za-z0-9._-]/_}
|
||||
mkdir -p "$dest"
|
||||
out=$dest/victory-saves-$id-$(date +%Y%m%d-%H%M%S).tar.gz
|
||||
if [ -e "$out" ]; then
|
||||
out=$dest/victory-saves-$id-$(date +%Y%m%d-%H%M%S)-$$.tar.gz
|
||||
fi
|
||||
if ! tar czf "$out.part" -C "$src" "${files[@]}"; then
|
||||
rm -f "$out.part"
|
||||
echo "saves: backup of $src failed; not updating" >&2
|
||||
exit 1
|
||||
fi
|
||||
mv "$out.part" "$out"
|
||||
chmod 600 "$out"
|
||||
echo "saves: $out"
|
||||
echo "saves: restore with: tar xzf \"$out\" -C \"$src\""
|
||||
|
||||
if (( keep > 0 )); then
|
||||
(
|
||||
cd "$dest"
|
||||
mapfile -t old < <(ls -1t victory-saves-$id-*.tar.gz 2>/dev/null | tail -n +$((keep + 1)))
|
||||
if (( ${#old[@]} )); then
|
||||
rm -f -- "${old[@]}"
|
||||
fi
|
||||
)
|
||||
fi
|
||||
done
|
||||
|
||||
if (( ! found )); then
|
||||
echo "saves: none found under $where, nothing to back up"
|
||||
fi
|
||||
30
update.sh
30
update.sh
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
# Merges the latest upstream main into the current branch, then builds.
|
||||
# The title's saves are backed up first, outside the checkout.
|
||||
# The title's saves are backed up first, outside local/.
|
||||
# usage: ./update.sh (UPSTREAM=remote and BRANCH=name to change them)
|
||||
set -euo pipefail
|
||||
if (( EUID == 0 )); then
|
||||
@ -13,29 +13,6 @@ if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Keep saves outside local/: an update that replaces local/ must not take the
|
||||
# only copy with it.
|
||||
backup_saves() {
|
||||
local src=${SAVES_DATA_DIR:-$PWD/local/data/7952987A}
|
||||
local dest=${SAVES_BACKUP_DIR:-$PWD/saves-backup}
|
||||
local files=()
|
||||
[ -d "$src/saves" ] && files+=(saves)
|
||||
[ -e "$src/storage/settings" ] && files+=(storage/settings)
|
||||
if (( ${#files[@]} == 0 )); then
|
||||
echo "saves: none at $src, nothing to back up"
|
||||
return 0
|
||||
fi
|
||||
mkdir -p "$dest"
|
||||
local out=$dest/victory-saves-$(date +%Y%m%d-%H%M%S).tar.gz
|
||||
if ! tar czf "$out.part" -C "$src" "${files[@]}"; then
|
||||
rm -f "$out.part"
|
||||
echo "saves: backup failed; not updating" >&2
|
||||
return 1
|
||||
fi
|
||||
mv "$out.part" "$out"
|
||||
echo "saves: $out"
|
||||
}
|
||||
|
||||
upstream=${UPSTREAM:-origin}
|
||||
branch=${BRANCH:-main}
|
||||
|
||||
@ -55,7 +32,10 @@ if (( new == 0 )); then
|
||||
else
|
||||
echo "$new new commits:"
|
||||
git log --format=' %h %an: %s' HEAD..FETCH_HEAD
|
||||
backup_saves
|
||||
if ! "$PWD/tools/backup-saves.sh"; then
|
||||
echo "saves: backup failed; not updating" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! git merge --no-edit FETCH_HEAD; then
|
||||
git merge --abort
|
||||
echo "conflicts: merge undone, $current is as before. Merge by hand: git merge $upstream/$branch"
|
||||
|
||||
Reference in New Issue
Block a user