From 341bcbea7d6cf0d5742c8622ba48107a192f12b9 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sun, 28 Apr 2024 18:04:56 +0200 Subject: [PATCH] feat: database backup script --- scripts/backup.sh | 24 ++++++++++++++++++++++++ scripts/store-backup.sh | 7 +++++++ 2 files changed, 31 insertions(+) create mode 100644 scripts/backup.sh create mode 100644 scripts/store-backup.sh diff --git a/scripts/backup.sh b/scripts/backup.sh new file mode 100644 index 000000000..dc58dec8c --- /dev/null +++ b/scripts/backup.sh @@ -0,0 +1,24 @@ +# Takes a backup of database Docker volume and compress into one .tar.gz +# file and upload to s3 package through s3cmd. +S3_BUCKET="s3://bigcapital-backup" + +# Generate the current date and time formatted as YYYY-MM-DD-HH-MM-SS +CURRENT_DATETIME=$(date +"%Y-%m-%d-%H-%M-%S") + +# Define the filename with the current date and time +FILE_NAME="bigcapital-mariadb-${CURRENT_DATETIME}.tar.gz" + +# Create a sample file (replace this with your actual file creation process) +echo "This is a sample file created on ${CURRENT_DATETIME}" > "$FILE_NAME" + +docker run --rm \ + --mount source=bigcapital_prod_mysql,target=/data/db \ + -v $(pwd):/backup \ + busybox \ + tar -czvf "/backup/$FILE_NAME" /data/db + +# Upload the file to S3 using s3cmd +s3cmd put "$FILE_NAME" "$S3_BUCKET/" + +# Remove the temporary file +rm "$FILE_NAME" diff --git a/scripts/store-backup.sh b/scripts/store-backup.sh new file mode 100644 index 000000000..0cf6667ec --- /dev/null +++ b/scripts/store-backup.sh @@ -0,0 +1,7 @@ + +# Store the backup. +docker run --rm \ + --mount source=bigcapital_dev_mysql,target=/data/db \ + -v $(pwd):/backup \ + busybox \ + tar -xzvf /backup/bigcapital-mariadb-2024-04-24-15-14-40.tar.gz -C / \ No newline at end of file