Skip to content

Instantly share code, notes, and snippets.

@antonioaguilar
Forked from lucaswilric/db_backup.sh
Created March 25, 2023 21:36
Show Gist options
  • Save antonioaguilar/0abbc6e0d7e8cdf836e120fbddac14e2 to your computer and use it in GitHub Desktop.
Save antonioaguilar/0abbc6e0d7e8cdf836e120fbddac14e2 to your computer and use it in GitHub Desktop.

Revisions

  1. @lucaswilric lucaswilric revised this gist Nov 24, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions db_backup.sh
    Original file line number Diff line number Diff line change
    @@ -5,9 +5,9 @@
    # NOT RECOMMENDED FOR LARGE DATABASES!

    # Dump a MySQL database
    # Don't put your password in here for real. Read this instead:
    # Read this for how to get your password into mysqldump:
    # https://dev.mysql.com/doc/refman/5.1/en/password-security-user.html
    mysqldump -u username --password=this_is_a_lame_password database > database.sql
    mysqldump -u username > database.sql

    # Or dump a PostgreSQL database. For this one, you'll need to put your credentials
    # in ~/.pgpass in this format:
  2. @lucaswilric lucaswilric revised this gist Nov 24, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion db_backup.sh
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,8 @@
    # NOT RECOMMENDED FOR LARGE DATABASES!

    # Dump a MySQL database
    # Don't put your password in here for real. Read this instead:
    # https://dev.mysql.com/doc/refman/5.1/en/password-security-user.html
    mysqldump -u username --password=this_is_a_lame_password database > database.sql

    # Or dump a PostgreSQL database. For this one, you'll need to put your credentials
    @@ -18,7 +20,7 @@ pg_dump --host=localhost --username=username database > database.sql
    gzip -N -9 database.sql

    # Encrypt
    openssl enc -aes-256-cbc -in database.sql.gz -out database.sql.gz.aes256cbc -pass pass:another_lame_password
    openssl enc -aes-256-cbc -in database.sql.gz -out database.sql.gz.aes256cbc -pass file:db_encryption.pass

    # Store
    mv database.sql.gz.aes256cbc /home/user/Dropbox/db-backups/`date +%Y%m%d%H%M%S`_database.sql.gz.aes256cbc
  3. @lucaswilric lucaswilric revised this gist Nov 24, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion db_backup.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    #!/bin/bash
    # This script dumps a database to SQL, compresses, encrypts and timestamps it, then saves it to Dropbox. Ideal for a cronjob.
    # It uses symmetric encryption, so guard your password carefully!
    # It uses symmetric encryption, so guard your password carefully.
    #
    # NOT RECOMMENDED FOR LARGE DATABASES!

    # Dump a MySQL database
    mysqldump -u username --password=this_is_a_lame_password database > database.sql
  4. @lucaswilric lucaswilric revised this gist Nov 24, 2012. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions db_backup.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    #!/bin/bash
    # This script dumps a database to SQL, compresses, encrypts and timestamps it, then saves it to Dropbox. Ideal for a cronjob.
    # It uses symmetric encryption, so guard your password carefully!

    # Dump a MySQL database
    mysqldump -u username --password=this_is_a_lame_password database > database.sql
    @@ -10,14 +12,14 @@ mysqldump -u username --password=this_is_a_lame_password database > database.sql
    #
    pg_dump --host=localhost --username=username database > database.sql

    # Compress
    # Compress: -9 means best, slowest encryption.
    gzip -N -9 database.sql

    # Encrypt
    openssl enc -aes-256-cbc -in database.sql.gz -out database.sql.gz.aes256cbc -pass pass:another_lame_password

    # Store
    mv database.sql.gz.aes256cbc /home/lucas/Dropbox/db-backups/`date +%Y%m%d%H%M%S`_database.sql.gz.aes256cbc
    mv database.sql.gz.aes256cbc /home/user/Dropbox/db-backups/`date +%Y%m%d%H%M%S`_database.sql.gz.aes256cbc

    # Clean up
    rm database.sql.gz
  5. @lucaswilric lucaswilric created this gist Nov 24, 2012.
    23 changes: 23 additions & 0 deletions db_backup.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #!/bin/bash

    # Dump a MySQL database
    mysqldump -u username --password=this_is_a_lame_password database > database.sql

    # Or dump a PostgreSQL database. For this one, you'll need to put your credentials
    # in ~/.pgpass in this format:
    #
    # hostname:port:database:username:password
    #
    pg_dump --host=localhost --username=username database > database.sql

    # Compress
    gzip -N -9 database.sql

    # Encrypt
    openssl enc -aes-256-cbc -in database.sql.gz -out database.sql.gz.aes256cbc -pass pass:another_lame_password

    # Store
    mv database.sql.gz.aes256cbc /home/lucas/Dropbox/db-backups/`date +%Y%m%d%H%M%S`_database.sql.gz.aes256cbc

    # Clean up
    rm database.sql.gz