Skip to main content
added 319 characters in body
Source Link

I'm trying to create a script that mysqldumps all my databases, creating an individual .sql file for each database and combines the output into backup-DATE.tar.gz.

I've gotten as far as being able to create the .sql backups, but the last hump I can't overcome due to my limited knowledge is how to combine all the .sql files into backup-DATE.tar.gz.

This is what I have so far:

mysql -N -u user -p'password' -e 'show databases' | while read dbname; do mysqldump --add-drop-table -u user -p'password' "$dbname" > /backuplocation/"$dbname".sql; done

This outputs all my databases into my backup location individually ie:

/backuplocation/
    /db1.sql
/backuplocation    /db2.sql
/backuplocation    /db3.sql

Is it possible to combine this output into backup-DATE.tar.gz with this strategy?

Edited to better explain my goal:

My goal is to run this script and get something like the following:

/backuplocation/
    /backup-DATE.tar.gz/
        /db1.sql
        /db2.sql
        /db3.sql

Instead of this:

/backuplocation/
    /db1.sql
    /db2.sql
    /db3.sql

I'm trying to create a script that mysqldumps all my databases, creating an individual .sql file for each database and combines the output into backup-DATE.tar.gz.

I've gotten as far as being able to create the .sql backups, but the last hump I can't overcome due to my limited knowledge is how to combine all the .sql files into backup-DATE.tar.gz.

This is what I have so far:

mysql -N -u user -p'password' -e 'show databases' | while read dbname; do mysqldump --add-drop-table -u user -p'password' "$dbname" > /backuplocation/"$dbname".sql; done

This outputs all my databases into my backup location individually ie:

/backuplocation/db1.sql
/backuplocation/db2.sql
/backuplocation/db3.sql

Is it possible to combine this output into backup-DATE.tar.gz with this strategy?

I'm trying to create a script that mysqldumps all my databases, creating an individual .sql file for each database and combines the output into backup-DATE.tar.gz.

I've gotten as far as being able to create the .sql backups, but the last hump I can't overcome due to my limited knowledge is how to combine all the .sql files into backup-DATE.tar.gz.

This is what I have so far:

mysql -N -u user -p'password' -e 'show databases' | while read dbname; do mysqldump --add-drop-table -u user -p'password' "$dbname" > /backuplocation/"$dbname".sql; done

This outputs all my databases into my backup location individually ie:

/backuplocation/
    /db1.sql
    /db2.sql
    /db3.sql

Is it possible to combine this output into backup-DATE.tar.gz with this strategy?

Edited to better explain my goal:

My goal is to run this script and get something like the following:

/backuplocation/
    /backup-DATE.tar.gz/
        /db1.sql
        /db2.sql
        /db3.sql

Instead of this:

/backuplocation/
    /db1.sql
    /db2.sql
    /db3.sql
Source Link

Combine the output of while loop into tar

I'm trying to create a script that mysqldumps all my databases, creating an individual .sql file for each database and combines the output into backup-DATE.tar.gz.

I've gotten as far as being able to create the .sql backups, but the last hump I can't overcome due to my limited knowledge is how to combine all the .sql files into backup-DATE.tar.gz.

This is what I have so far:

mysql -N -u user -p'password' -e 'show databases' | while read dbname; do mysqldump --add-drop-table -u user -p'password' "$dbname" > /backuplocation/"$dbname".sql; done

This outputs all my databases into my backup location individually ie:

/backuplocation/db1.sql
/backuplocation/db2.sql
/backuplocation/db3.sql

Is it possible to combine this output into backup-DATE.tar.gz with this strategy?