Modification of MySQLDump-files before compression needed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Modification of MySQLDump-files before compression needed
# 8  
Old 03-07-2013
Thank's a lot!

The printf did it - for those who like to have the complete script:
Code:
#!/bin/sh


#ATTENTION! this script MIGHT NOT work for database names with blanks!!! (tables work fine)

BACKUPDIR="/media/DBSaves/Backup";
DBFILTER="(database_x|database_y)";
MYSQLDUMP="$(which mysqldump) --opt";

MYSQL=$(which mysql);
GZIP=$(which pbzip2);
NICE=$(which nice);
EGREP=$(which egrep);

DBS=$($MYSQL -Bse "show databases");

for db in $DBS
do

    if (echo $db | $EGREP $DBFILTER > /dev/null);
    then
      # for import to $TBL blanks in table names are replaced by '@' otherways the tablename would be split by the blank.
      # The '@' is replaced 4 lines later again otherways mysqldump can not find the table
      # IF YOU USE '@' in table names - replace it in the sed-commands with your favourite string ;)
      TBL=$($MYSQL -Bse "show tables from $db" | sed s/\ /@/g);

      for tb in $TBL
      do
         TableNameKorr=`echo $tb | sed s/@/\ /g;`
         FILENAME="$db""_""$tb-`date +%Y%m%d_%H%M%S`.sql.gz";
         UseAnweisung="CREATE DATABASE  IF NOT EXISTS \`$db\` /*!40100 DEFAULT CHARACTER SET latin1 */;USE \`$db\`;"
         {
            $NICE -n 20 printf '%s\n' "$UseAnweisung"
            $NICE -n 20 $MYSQLDUMP "$db" "$TableNameKorr"
            } |
              $NICE -n 20 $GZIP -c > "$BACKUPDIR/$FILENAME"
      done

    fi

done

exit 0

For clarification:

The Use-Statement is needed by the MySQL-Workbench otherways the import of single tables is not possible from the graphical user interface. Mysqldump does not include this statement (and the MySQL-Workbench can not be operated by scripts Smilie )

Last edited by gogo555; 03-07-2013 at 08:11 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Needed shell script to read txt file and do some modification

Hi ...programmers... I need a shell script to perform some specific task.. my txt file looks like this netcdf new { dimensions: XAX1_11 = 11 ; variables: double XAX1_11(XAX1_11) ; XAX1_11:point_spacing = "even" ; XAX1_11:axis = "X" ; float DEPTH(XAX1_11) ;... (19 Replies)
Discussion started by: Akshay Hegde
19 Replies

2. Shell Programming and Scripting

Compression - Exclude huge files

I have a DB folder which sizes to 60GB approx. It has logs which size from 500MB - 1GB. I have an Installation which would update the DB. I need to backup this DB folder, just incase my Installation FAILS. But I do not need the logs in my backup. How do I exclude them during compression (tar)? ... (2 Replies)
Discussion started by: DevendraG
2 Replies

3. UNIX for Dummies Questions & Answers

Modification of Two Files

I have a script that produces two output files each containing the same number of lines <file1.txt> and <file2.txt>. What I need to do is combine both files into a new file <file3.txt> where line 1 of <file1.txt> is put to the right (and on the same line) as line 1 of <file2.txt> and then the same... (5 Replies)
Discussion started by: theref
5 Replies

4. Shell Programming and Scripting

Rename old files with last modification date

Hi everyone, I have files like file1_Mod.txt, file2_Mod.txt. I want to rename the old files with the last modification date. I write the below script to rename with current date, but I donīt know how to use "date -r" to get the last modification date with the same format I have below... (5 Replies)
Discussion started by: cgkmal
5 Replies

5. Shell Programming and Scripting

Help needed for mysqldump command

I want to take a backup of a database and redirect the output of the whole process to a log file. I am using the below command: mysqldump -A --add-drop-table > mysql-daily-backup.sql &> /tmp/backup_log/mysql.log Is there anything wrong with the syntax? ---------- Post updated at 08:32 PM... (0 Replies)
Discussion started by: proactiveaditya
0 Replies

6. UNIX for Advanced & Expert Users

Help with sorting files according to modification date

Hi, I was very surprised to not be able to find an answer to this question despite my best efforts in Google and elsewhere. Maybe it's a good thing as it forced me to finally become a member in this great forum that i use frequently. Ok my question: I want to be able to sort files inside a... (3 Replies)
Discussion started by: stavros
3 Replies

7. Shell Programming and Scripting

7za compression,urgent help needed!!!

Hi all, I am manipulating a ram disk image.that is 7za compressed... But i somehow am not able to get a hold of the command line for 7za compression and i need urgent help!!! this is what am doing... gzcat /path/to/directory/x86.microroot >/tmp/microroot x=`lofiadm -a /tmp/microroot` mount... (0 Replies)
Discussion started by: wrapster
0 Replies

8. UNIX for Advanced & Expert Users

Best compression for log files?

I have been doing some investigation into a log file from one of my systems, and the means which I currently use to compress and rotate it. I am looking for something smarter than gzip, faster than bzip2, and that can match or beat "my script" (which is slow as heck, but WAY better compression... (2 Replies)
Discussion started by: jjinno
2 Replies

9. UNIX for Dummies Questions & Answers

Last modification times of files less than 6 months old

How do I get the modification time for files less than 6 months old? (It seems for fles as old or older than this I get to see only the day,month and year. I tried the option -u but it gives me the last accessed time) (1 Reply)
Discussion started by: Abhishek Ghose
1 Replies
Login or Register to Ask a Question