-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwaybak.sh
executable file
·134 lines (107 loc) · 3 KB
/
waybak.sh
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env bash
# Waybak - Simple Waydroid Backup and Restore Tool
set -e # Exit on any error
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
# Default backup directory relative to script's path
BACKUP_DIR="$SCRIPT_DIR/backups"
# Waydroid data directories
WAYDROID_USER_HOME="$HOME/.local/share/waydroid"
WAYDROID_VAR="/var/lib/waydroid"
WAYDROID_ETC="/etc/waydroid-extra/images"
# Function to check if Waydroid is installed
check_waydroid_installed() {
if ! command -v waydroid >/dev/null 2>&1; then
echo "Waydroid is not installed. Please install it before running this script."
exit 1
fi
}
# Function to stop Waydroid session
stop_waydroid() {
echo "Stopping Waydroid session..."
sudo waydroid session stop || true
}
# Function to backup Waydroid data
backup_waydroid() {
stop_waydroid
echo "Starting backup..."
mkdir -p "$BACKUP_DIR"
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
BACKUP_FILE="$BACKUP_DIR/waydroid_backup_$TIMESTAMP.tar.gz"
echo "Creating backup at $BACKUP_FILE..."
sudo tar -czf "$BACKUP_FILE" \
"$WAYDROID_USER_HOME" \
"$WAYDROID_VAR" \
"$WAYDROID_ETC" 2>/dev/null || true
echo "Backup completed successfully."
}
# Function to restore Waydroid data
restore_waydroid() {
stop_waydroid
echo "Starting restore..."
# Check for available backups
shopt -s nullglob
backups=("$BACKUP_DIR"/*.tar.gz)
shopt -u nullglob
if [ ${#backups[@]} -eq 0 ]; then
echo "No backups found in $BACKUP_DIR."
exit 1
fi
echo "Available backups:"
select backup_file in "${backups[@]}"; do
if [ -n "$backup_file" ]; then
BACKUP_FILE="$backup_file"
break
else
echo "Invalid selection. Please try again."
fi
done
# Confirmation prompt accepting 'y' or 'n' and re-prompting on invalid input
while true; do
echo -n "This will overwrite your current Waydroid data. Are you sure? (y/n): "
read -r CONFIRM
case "$CONFIRM" in
y|Y)
break
;;
n|N)
echo "Restore cancelled."
return
;;
*)
echo "Invalid input. Please enter 'y' or 'n'."
;;
esac
done
echo "Cleaning existing Waydroid data..."
# Clean files within the directories but keep the directories themselves
sudo rm -rf "$WAYDROID_USER_HOME/"* \
"$WAYDROID_VAR/"* \
"$WAYDROID_ETC/"*
echo "Restoring from $BACKUP_FILE..."
# Extract backup
sudo tar -xzf "$BACKUP_FILE" -C /
echo "Restore completed successfully."
}
# Function to display menu
show_menu() {
echo
echo "Waybak - Simple Waydroid Backup and Restore Tool"
echo "-----------------------------------------------"
echo "1) Backup"
echo "2) Restore"
echo "3) Exit"
echo -n "Enter your choice [1-3]: "
read -r choice
case $choice in
1) backup_waydroid ;;
2) restore_waydroid ;;
3) exit 0 ;;
*) echo "Invalid choice." ;;
esac
}
# Main script logic
check_waydroid_installed
while true; do
show_menu
done