forked from tosca07/picochess
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrestore-books-games-from-backup.sh
More file actions
executable file
·46 lines (38 loc) · 1.15 KB
/
Copy pathrestore-books-games-from-backup.sh
File metadata and controls
executable file
·46 lines (38 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh
# restore-books-games-from-backup.sh – Restore book/game resources from backup
# Run as user pi. Complements move-books-games-to-backup.sh.
#
REPO_DIR=${REPO_DIR:-/opt/picochess}
BOOKS_DIR="$REPO_DIR/books"
GAMES_DIR="$REPO_DIR/gamesdb"
BACKUP_DIR_BASE="${HOME}/pico_backups"
BACKUP_DIR="$BACKUP_DIR_BASE/current/books_games_backup"
if [ ! -d "$REPO_DIR" ]; then
echo "Repository directory $REPO_DIR not found. Aborting." >&2
exit 1
fi
if [ ! -d "$BACKUP_DIR" ]; then
echo "Backup directory $BACKUP_DIR not found. Nothing to restore." >&2
exit 1
fi
restore_dir() {
SRC="$1"
DST="$2"
NAME="$3"
if [ -d "$SRC" ]; then
rm -rf "$DST"
mv "$SRC" "$DST" || {
echo "Error: Failed to restore $NAME directory." >&2
return 1
}
chown -R pi:pi "$DST" 2>/dev/null || true
echo "Restored $NAME directory."
else
echo "No $NAME directory in backup – skipping."
fi
return 0
}
restore_dir "$BACKUP_DIR/books" "$BOOKS_DIR" "books" || exit 1
restore_dir "$BACKUP_DIR/gamesdb" "$GAMES_DIR" "gamesdb" || exit 1
echo "Books and games restored to $REPO_DIR."
exit 0