Skip to content

Instantly share code, notes, and snippets.

@Androz2091
Last active January 31, 2024 13:22
Show Gist options
  • Save Androz2091/f041e308fa0425d8f0165c4bf503d710 to your computer and use it in GitHub Desktop.
Save Androz2091/f041e308fa0425d8f0165c4bf503d710 to your computer and use it in GitHub Desktop.
Save data with BackBlaze

Authenticate

  • sudo docker run --rm -it -v b2:/root backblazeit/b2:latest authorize-account

this will save your credentials in the b2 volume, so next time you'll run commands you'll be authenticated

Vault

Warning: attachments are created under the user the docker compose is started with (be aware that the backup tool may not have the permissions to read the files)

#!/bin/bash
TIMESTAMP=`date +%F-%H%M`
# Directory to archive
SOURCE_DIR="/home/debian/services/cloud/files"
BACKUP_NAME="cloud-$TIMESTAMP"
BACKUPS_DIR="/home/debian/CLOUD_BACKUPS"
BB_BUCKET_NAME="poca-cloud"
# Create the archive
tar -zcvf $BACKUPS_DIR/$BACKUP_NAME.tar.gz $SOURCE_DIR
# Upload to BackBlaze
docker run --rm -v b2:/root -v $BACKUPS_DIR:/data backblazeit/b2:latest upload-file $BB_BUCKET_NAME /data/$BACKUP_NAME.tar.gz cloud.tar.gz
# Delete the archives (except the current one) from the backups dir
find $BACKUPS_DIR/ ! -name $BACKUP_NAME.tar.gz -type f -exec rm -f {} +
# Log
echo "Backup of cloud completed"
#!/bin/bash
TIMESTAMP=`date +%F-%H%M`
BB_BUCKET_NAME="poca-databases"
PG_PATH="/usr/lib/postgresql/15/bin/pg_dump"
PG_USER=""
PG_PASSWORD=""
for db in `PGPASSWORD="$PG_PASSWORD" psql -U $PG_USER -h localhost -d postgres -t -c 'select datname from pg_database where not datistemplate' | grep '\S' | awk NF`; do
echo "Backing up $db"
BACKUPS_DIR="/home/debian/PG_BACKUPS/$db"
BACKUP_NAME="$db-$TIMESTAMP"
# Make the backups directory if it doesn't exist
mkdir -p $BACKUPS_DIR
# Dump the Postgres database
PGPASSWORD=$PG_PASSWORD $PG_PATH -F p -f $BACKUPS_DIR/$BACKUP_NAME.sql -U $PG_USER $db -h localhost
# Then delete the rest of the files
find $BACKUPS_DIR/ ! -name $BACKUP_NAME.sql -type f -exec rm -f {} +
# Make a tar file of the dump
tar -zcvf $BACKUPS_DIR/$BACKUP_NAME.tar.gz $BACKUPS_DIR/$BACKUP_NAME.sql
docker run --rm -v b2:/root -v $BACKUPS_DIR:/data backblazeit/b2:latest upload-file $BB_BUCKET_NAME /data/$BACKUP_NAME.tar.gz $db.tar.gz
# Log
echo "Backup of $db database completed"
done
#!/bin/bash
TIMESTAMP=`date +%F-%H%M`
# Directory to archive
SOURCE_DIR="/home/debian/services/vaultwarden/data"
BACKUP_NAME="vault-$TIMESTAMP"
BACKUPS_DIR="/home/debian/VAULT_BACKUPS"
BB_BUCKET_NAME="poca-vault"
# Clear old files
find $BACKUPS_DIR/ ! -name *.tar.gz -type f -exec rm -f {} +
# Create the archive
mkdir $BACKUPS_DIR/$BACKUP_NAME
sqlite3 $SOURCE_DIR/db.sqlite3 ".backup '$BACKUPS_DIR/$BACKUP_NAME/db.sqlite3'"
cp -r $SOURCE_DIR/attachments $BACKUPS_DIR/$BACKUP_NAME
cp -r $SOURCE_DIR/sends $BACKUPS_DIR/$BACKUP_NAME
cp -r $SOURCE_DIR/*.pem $BACKUPS_DIR/$BACKUP_NAME
tar -zcvf $BACKUPS_DIR/$BACKUP_NAME.tar.gz $BACKUPS_DIR/$BACKUP_NAME
# Upload to BackBlaze
docker run --rm -v b2:/root -v $BACKUPS_DIR:/data backblazeit/b2:latest upload-file $BB_BUCKET_NAME /data/$BACKUP_NAME.tar.gz vault.tar.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment