Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backup and restore feature #132

Merged
merged 10 commits into from
Dec 3, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
implement restore function
  • Loading branch information
aleskxyz authored Dec 3, 2023
commit db1b88d09873c64eceaa4becdd516aba1ce9d88e
44 changes: 33 additions & 11 deletions reality-ezpz.sh
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ function parse_args {
fi

if [[ -n ${args[restore]} ]]; then
restore
args[restart]=true
restore ${args[restore]}
fi

if [[ ${args[uninstall]} == true ]]; then
Expand All @@ -351,27 +352,48 @@ function parse_args {
if [[ -n ${args[warp_license]} ]]; then
args[warp]=ON
fi

}

function backup {
lcoal backup_name
local backup_name
local backup_file_url
local exit_code
backup_name=reality-ezpz-backup-$(date +%Y-%m-%d_%H-%M-%S).tar.gz
tar -czf /tmp/${backup_name} -C /opt/reality-ezpz/ ./
if ! backup_file_url=$(curl -fsS --upload-file /tmp/${backup_name} https://free.keep.sh); then
rm -f /tmp/${backup_name}
tar -czf "/tmp/${backup_name}" -C "${config_path}" ./
if ! backup_file_url=$(curl -fsS --upload-file "/tmp/${backup_name}" https://free.keep.sh); then
rm -f "/tmp/${backup_name}"
echo "Error in uploading backup file"
exit 1
fi
rm -f /tmp/${backup_name}
rm -f "/tmp/${backup_name}"
echo "You can download the backup file from this URL:"
echo ${backup_file_url}
echo "${backup_file_url}"
echo "The URL is only valid for 24h."
exit 0
}

function restore {
local backup_file=$1
local temp_file
if [[ ! -r ${backup_file} ]]; then
temp_file=$(mktemp -u)
if ! curl -fSsL "${backup_file}" -o "${temp_file}"; then
echo "Cannot download or find backup file"
exit 1
fi
backup_file="${temp_file}"
fi
if ! tar -tzf "${backup_file}" | grep -q config; then
echo "The provided file is not a reality-ezpz backup file."
rm -f "${temp_file}"
exit 1
fi
rm -rf "${config_path}"
mkdir -p "${config_path}"
tar -xzf "${backup_file}" -C "${config_path}"
rm -f "${temp_file}"
}

function dict_expander {
local -n dict=$1
for key in "${!dict[@]}"; do
Expand Down Expand Up @@ -743,7 +765,7 @@ services:
BOT_ADMIN: ${config[tgbot_admins]}
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ../:/opt/reality-ezpz
- ../:${config_path}
- /etc/docker/:/etc/docker/
networks:
- tgbot
Expand Down Expand Up @@ -889,7 +911,7 @@ EOF
function generate_tgbot_dockerfile {
cat >"${path[tgbot_dockerfile]}" << EOF
FROM ${image[python]}
WORKDIR /opt/reality-ezpz/tgbot
WORKDIR ${config_path}/tgbot
RUN apk add --no-cache docker-cli-compose curl bash newt libqrencode sudo openssl jq
RUN pip install --no-cache-dir python-telegram-bot==13.5
CMD [ "python", "./tgbot.py" ]
Expand Down Expand Up @@ -1372,7 +1394,7 @@ function upgrade {
local warp_id
if [[ -e "${HOME}/reality/config" ]]; then
${docker_cmd} --project-directory "${HOME}/reality" down --remove-orphans --timeout 2
mv -f "${HOME}/reality" /opt/reality-ezpz
mv -f "${HOME}/reality" ${config_path}
fi
uuid=$(grep '^uuid=' "${path[config]}" 2>/dev/null | cut -d= -f2 || true)
if [[ -n $uuid ]]; then
Expand Down