Unfortunately these files need modification - they have to start with the following line(s):
Code:
CREATE DATABASE IF NOT EXISTS `Database_X` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `Database_X`;
which is not supported by mysqldump (when exporting single tables)
With the echo-command I can produce the files I want, but all the linebreaks are missing - causing the file to crash at import...
With the echo-command I can produce the files I want, but all the linebreaks are missing - causing the file to crash at import...
Just wrap the variable in quotes (otherwise echo will interpret the string as a bunch of separate arguments):
Code:
[user@host] cat test.sh
#!/bin/ksh
UseAnweisung='CREATE DATABASE IF NOT EXISTS `Database_X` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `Database_X`;'
echo "${UseAnweisung}"
[user@host] ./test.sh
CREATE DATABASE IF NOT EXISTS `Database_X` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `Database_X`;
this command produces a text-output with linebreaks that vanish when the echo command combines USE_Anweisung and the text-output
What the script should do is:
1. create a dump-text-output with MySQLDump
2. add a (short) text-prefix in front of the output from #1
3. compress it to somwhere ... avoid writing temporary files to disk ... if possible.
You'll need more code. You may try something like this.
The code assumes that:
- your shell supports ANSI escape sequences, otherwise you'll need to enter a literal TAB in the first assignment
- your shell supports the ${variable/pattern/string} parameter expansion
- your client is configured to connect to MySQL directly (i.e. it doesn't prompt for username and password)
Code:
_tab=$'\t'
mysql -BNe'show databases' |
while read _db; do
mysql -BNe"show create database $_db; show tables from $_db"
done |
while read _data; do
case $_data in
( *"CREATE DATABASE"* )
_db_ddl=${_data#*$_tab}
_db_ddl=${_db_ddl/DATABASE/DATABASE IF NOT EXISTS}
_db=${_data%%$_tab*}
continue ;;
esac
{
printf '%s;\nuse %s;\n' "$_db_ddl" "$_db"
mysqldump "$_db" "$_data"
} |
gzip > "$_db"_"$_data".dmp.gz
done
The script will back up all tables from all databases. If you want to backup only a specific database(s),
you could use:
Code:
show databases where `Database` in (db1, db2, ...)
but unfortunately the output of `$MYSQLDUMP $db $tb` looses it's linebreaks when the echo-command is working. That's the reason why I used cat, and 2 files, but in general I avoid writing this temporary data to the disk - maybe cat works with some kind of:
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)
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)
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)
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)
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)
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)
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)
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)
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)