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

Feature for compressing dump file #2

Open
wants to merge 4 commits into
base: master
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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

SUPABASE_URL=YOUR_SUPABASE_URL
SUPABASE_ANON_KEY=YOUR_SUPABASE_ANON_KEY
SUPABASE_BUCKET=YOUR_SUPABASE_BUCKET

# Docker
CONTAINER_NAME=postgres
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.env
src/file/dump.sql
src/file/dump.sql
src/file/dump.sql.tar.gz
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ include .env
create-backup:
ifeq ($(strip $(DATABASE_EXCLUDE_TABLES_DATA)),)
@echo "Creating backup of all tables data"
@docker exec -t ${CONTAINER_NAME} pg_dump -c --user ${DATABASE_USER} --dbname=${DATABASE_NAME} > src/file/dump.sql
@docker exec -t ${CONTAINER_NAME} pg_dump -c --user ${DATABASE_USER} --dbname=${DATABASE_NAME} > src/file/dump.sql && cd src/file && tar -czvf dump.sql.tar.gz dump.sql && rm dump.sql

else
@docker exec -t ${CONTAINER_NAME} pg_dump -c --user ${DATABASE_USER} --dbname=${DATABASE_NAME} --exclude-table-data=${DATABASE_EXCLUDE_TABLES_DATA} > src/file/dump.sql
@docker exec -t ${CONTAINER_NAME} pg_dump -c --user ${DATABASE_USER} --dbname=${DATABASE_NAME} --exclude-table-data=${DATABASE_EXCLUDE_TABLES_DATA} > src/file/dump.sql && tar -czvf src/file/dump.sql.tar.gz src/file/dump.sql && rm src/file/dump.sql
endif
@echo "Backup created, now upload it to Supabase"
@docker run --rm -v "${PWD}:/app" -w /app node:16.14.2 /bin/bash -c "yarn install; node src/index.js"
Expand Down
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ const { createClient } = require('@supabase/supabase-js')

const supabaseUrl = process.env.SUPABASE_URL
const supabaseAnonKey = process.env.SUPABASE_ANON_KEY
const supabaseBucket = process.env.SUPABASE_BUCKET

const supabase = createClient(supabaseUrl, supabaseAnonKey)

const uploadFile = async () => {
// generate a file name with current date
const fileName = `${new Date().toISOString()}.sql`
const buf = fs.readFileSync(__dirname + '/file/dump.sql');
const fileName = `${new Date().toISOString()}.tar`
const buf = fs.readFileSync(__dirname + '/file/dump.sql.tar.gz');

const { data, error } = await supabase.storage
.from('tavivo-backup')
.from(supabaseBucket)
.upload(fileName, buf)

console.log('🚀 ~ file: index.js ~ line 13 ~ uploadFile ~ error', error)
Expand Down