Skip to content

Instantly share code, notes, and snippets.

@stnguyen90
Last active September 18, 2024 09:42
Show Gist options
  • Save stnguyen90/fee636ff652b8ecbf761935b2aa254fb to your computer and use it in GitHub Desktop.
Save stnguyen90/fee636ff652b8ecbf761935b2aa254fb to your computer and use it in GitHub Desktop.
Backup & Restore Appwrite
#!/bin/bash
mkdir -p backup
docker compose exec mariadb sh -c 'exec mysqldump --all-databases --add-drop-database -u"$MYSQL_USER" -p"$MYSQL_PASSWORD"' > ./backup/dump.sql
appwrite_volumes=(uploads cache config certificates functions)
for volume in ${appwrite_volumes[@]}; do
mkdir -p backup && docker run --rm --volumes-from "$(docker compose ps -q appwrite)" -v $PWD/backup:/backup ubuntu bash -c "cd /storage/$volume && tar cvf /backup/$volume.tar ."
done
docker run --rm --volumes-from "$(docker compose ps -q appwrite-worker-deletes)" -v $PWD/backup:/backup ubuntu bash -c "cd /storage/builds && tar cvf /backup/builds.tar ."
cp docker-compose.yml backup
cp .env backup
if [ -f docker-compose.override.yml ]; then
cp docker-compose.override.yml backup
fi
#!/bin/bash
docker compose exec -T mariadb sh -c 'exec mysql -u"$MYSQL_USER" -p"$MYSQL_PASSWORD"' < ./backup/dump.sql
appwrite_volumes=(uploads cache config certificates functions)
for volume in ${appwrite_volumes[@]}; do
if [ ! -f "./backup/$volume.tar" ]; then
continue
fi
docker run --rm --volumes-from "$(docker compose ps -q appwrite)" -v $PWD/backup:/restore ubuntu bash -c "cd /storage/$volume && tar xvf /restore/$volume.tar --strip 1"
done
if [ ! -f "./backup/builds.tar" ]; then
exit 0
fi
docker run --rm --volumes-from "$(docker compose ps -q appwrite-worker-deletes)" -v $PWD/backup:/restore ubuntu bash -c "cd /storage/builds && tar xvf /restore/builds.tar --strip 1"
#!/bin/bash
set -e # exit when any command fails
# create a gzipped archive of the backup
timestamp=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
tar -zcf "./backup-$timestamp.tar.gz" backup
# delete the backup folder
rm -rf backup
@FuadEfendi
Copy link

How to do it on MacOS? thanks

@FuadEfendi
Copy link

FuadEfendi commented Oct 3, 2022

I got it ;)

Use manual installation on MacOS, https://appwrite.io/docs/installation#manual

  • do not use automated script.

With manual installation, you create "appwrite" folder with two files; after installation, backup script will run from it without any issues.

@stnguyen90
Copy link
Author

  • do not use automated script.

@FuadEfendi, FYI the install command creates an appwrite folder with the docker-compose.yml and .env files.

@FuadEfendi
Copy link

FuadEfendi commented Oct 3, 2022

stnguyen90, where it creates it? In LinuxKit VM run on top of MacOS? Yes I saw log messages; there is no such path: /usr/src/code, neither on Mac, nor in Linux VM.

Manual installation is simpler than automated, and it works.

Contradictory, you have to click keys on keyboard less times with manual installation than with so-called "automated".

@stnguyen90
Copy link
Author

@FuadEfendi,

where it creates it?

The appwrite folder is created in the folder where the install command is executed. Notice the volume mount: --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw

click keys on keyboard less times with manual installation

The 1 command installation makes it really easy for newcomers as it prompts for some values rather than requiring users to scour the docker-compose.yml or .env file for what to update.

@FuadEfendi
Copy link

Thank you Steven!

@venkata-reddy-dev
Copy link

venkata-reddy-dev commented Mar 18, 2023

@stnguyen90 it would be great if you add this scripts links in docs: https://appwrite.io/docs/production

And alos i feel dedicated section is needed in docs for backup & restore

@chhinsras
Copy link

image
In windows 11

@stnguyen90
Copy link
Author

I've updated the restore script to skip over any tar files that don't exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment