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

backup: Use the default zulip backup system #262

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,32 @@ to `/etc/ssl/certs/ca-certificates.crt`.

At this point you are ready to build Zulip.

### Backups and restore

Zulip has built in support for creating and restoring backups. Do read
the [Backups, export and import][backups-export-import] documentation first
before continuing.

Here is an example on how you can run the backup command using docker-compose.
```
docker-compose exec -u zulip zulip /home/zulip/deployments/current/manage.py backup --output /data/backups/backup-file-name.tar.gz
```
The backup file in above example is stored in /data/backups directory. Since backups
directory is present inside the docker volume, the backup export can be accessed
from the host machine and is unaffected if the container is destroyed. The `/data/backups`
directory is automatically created during the container creation.

The backup can be restored using `scripts/setup/restore-backup` script. For example
```
docker-compose exec zulip /home/zulip/deployments/current/scripts/setup/restore-backup /data/backups/backup-file-name.tar.gz
```

You can restore the backup which you created in another docker-compose installation
by copying the backup file to `backups` directory in zulip server's volume storage directory
(eg `/opt/docker/zulip/zulip/backups`) in your host machine and running the command above.

[backups-export-import]: https://zulip.readthedocs.io/en/latest/production/maintain-secure-upgrade.html#backups

## Running a Zulip server with Kubernetes

A Kubernetes pod file is in the `kubernetes/` folder; you can run it
Expand Down
83 changes: 1 addition & 82 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ ZULIP_AUTH_BACKENDS="${ZULIP_AUTH_BACKENDS:-EmailAuthBackend}"
ZULIP_RUN_POST_SETUP_SCRIPTS="${ZULIP_RUN_POST_SETUP_SCRIPTS:-True}"
# Zulip user setup
FORCE_FIRST_START_INIT="${FORCE_FIRST_START_INIT:-False}"
# Auto backup settings
AUTO_BACKUP_ENABLED="${AUTO_BACKUP_ENABLED:-True}"
AUTO_BACKUP_INTERVAL="${AUTO_BACKUP_INTERVAL:-30 3 * * *}"
# Zulip configuration function specific variable(s)
SPECIAL_SETTING_DETECTION_MODE="${SPECIAL_SETTING_DETECTION_MODE:-}"
MANUAL_CONFIGURATION="${MANUAL_CONFIGURATION:-false}"
Expand All @@ -56,6 +53,7 @@ prepareDirectories() {
rm -rf /home/zulip/uploads
ln -sfT "$DATA_DIR/uploads" /home/zulip/uploads
chown zulip:zulip -R "$DATA_DIR/uploads"
chown zulip:zulip -R "$DATA_DIR/backups"
# Link settings folder
if [ "$LINK_SETTINGS_TO_DATA" = "True" ] || [ "$LINK_SETTINGS_TO_DATA" = "true" ]; then
# Create settings directories
Expand Down Expand Up @@ -279,15 +277,6 @@ zulipConfiguration() {
fi
echo "Zulip configuration succeeded."
}
autoBackupConfiguration() {
if [ "$AUTO_BACKUP_ENABLED" != "True" ] && [ "$AUTO_BACKUP_ENABLED" != "true" ]; then
rm -f /etc/cron.d/autobackup
echo "Auto backup is disabled. Continuing."
return 0
fi
printf 'MAILTO=""\n%s cd /;/entrypoint.sh app:backup\n' "$AUTO_BACKUP_INTERVAL" > /etc/cron.d/autobackup
echo "Auto backup enabled."
}
initialConfiguration() {
echo "=== Begin Initial Configuration Phase ==="
prepareDirectories
Expand All @@ -301,7 +290,6 @@ initialConfiguration() {
authenticationBackends
zulipConfiguration
fi
autoBackupConfiguration
echo "=== End Initial Configuration Phase ==="
}
# === bootstrappingEnvironment ===
Expand Down Expand Up @@ -439,67 +427,6 @@ appManagePy() {
set +e
exec su zulip -c "/home/zulip/deployments/current/manage.py $(printf '%q ' "$COMMAND" "$@")"
}
appBackup() {
echo "Starting backup process ..."
if [ -d "/tmp/backup-$(date "%D-%H-%M-%S")" ]; then
echo "Temporary backup folder for \"$(date "%D-%H-%M-%S")\" already exists. Aborting."
echo "Backup process failed. Exiting."
exit 1
fi
local BACKUP_FOLDER
BACKUP_FOLDER="/tmp/backup-$(date "%D-%H-%M-%S")"
mkdir -p "$BACKUP_FOLDER"
waitingForDatabase
pg_dump -h "$DB_HOST" -p "$DB_HOST_PORT" -U "$DB_USER" "$DB_NAME" > "$BACKUP_FOLDER/database-postgres.sql"
tar -zcvf "$DATA_DIR/backups/backup-$(date "%D-%H-%M-%S").tar.gz" "$BACKUP_FOLDER/"
rm -r "${BACKUP_FOLDER:?}/"
echo "Backup process succeeded."
exit 0
}
appRestore() {
echo "Starting restore process ..."
if [ -z "$(ls -A "$DATA_DIR/backups/")" ]; then
echo "No backups to restore found in \"$DATA_DIR/backups/\"."
echo "Restore process failed. Exiting."
exit 1
fi
while true; do
local backups=("$DATA_DIR"/backups/*)
printf '|-> %s\n' "${backups[@]#"$DATA_DIR"/backups/}"
echo "Please enter backup filename (full filename with extension): "
read -r BACKUP_FILE
if [ -z "$BACKUP_FILE" ]; then
echo "Empty filename given. Please try again."
echo ""
continue
fi
if [ ! -e "$DATA_DIR/backups/$BACKUP_FILE" ]; then
echo "File \"$BACKUP_FILE\" not found. Please try again."
echo ""
fi
break
done
echo "File \"$BACKUP_FILE\" found."
echo ""
echo "==============================================================="
echo "!! WARNING !! Your current data will be deleted!"
echo "!! WARNING !! YOU HAVE BEEN WARNED! You can abort with \"CTRL+C\"."
echo "!! WARNING !! Waiting 10 seconds before continuing ..."
echo "==============================================================="
echo ""
local TIMEOUT
for TIMEOUT in {10..1}; do
echo "$TIMEOUT"
sleep 1
done
echo "!! WARNING !! Starting restore process ... !! WARNING !!"
waitingForDatabase
tar -zxvf "$DATA_DIR/backups/$BACKUP_FILE" -C /tmp
psql -h "$DB_HOST" -p "$DB_HOST_PORT" -U "$DB_USER" "$DB_NAME" < "/tmp/$(basename "$BACKUP_FILE" | cut -d. -f1)/database-postgres.sql"
rm -r "/tmp/$(basename | cut -d. -f1)/"
echo "Restore process succeeded. Exiting."
exit 0
}
appCerts() {
configureCerts
}
Expand All @@ -508,8 +435,6 @@ appHelp() {
echo "> app:help - Show this help menu and exit"
echo "> app:version - Container Zulip server version"
echo "> app:managepy - Run Zulip's manage.py script (defaults to \"shell\")"
echo "> app:backup - Create backups of Zulip instances"
echo "> app:restore - Restore backups of Zulip instances"
echo "> app:certs - Create self-signed certificates"
echo "> app:run - Run the Zulip server"
echo "> [COMMAND] - Run given command with arguments in shell"
Expand All @@ -530,12 +455,6 @@ case "$1" in
shift 1
appManagePy "$@"
;;
app:backup)
appBackup
;;
app:restore)
appRestore
;;
app:certs)
appCerts
;;
Expand Down