I’ve tried using previously accepted solutions for my problem, but they aren’t working:
Example "id_list"
[jlefler@server ~]$ cat id_list | tail -10
17900018
17900019
17900020
17900021
17900022
17900023
17900024
17900025
17900026
17900027[jlefler@server ~]$ cat id_list |wc -l
51624
Command I’m trying to execute to dump 2000 id’s at a time:
xargs -a id_list -d 'n' -n 2000 sh -c 'mysqldump -uuser -ppassword --compact --no-create-info db table_name --where="id in ($0 $@)" >> dump.sql' x
However I get this unexpected output:
[jlefler@server ~]$ xargs -a id_list -d 'n' -n 2000 sh -c 'mysqldump -uuser -ppassword --compact --no-create-info db table_name --where="id in ($0 $@)" >> dump.sql' x
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17851966
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17853966
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17855967
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17857967
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17859975
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17861978
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17863978
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17865978
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17867978
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17869978
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17871978
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17873979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17875979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17877979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17879979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17881979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17883979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17885979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17887979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17889979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17891979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17893979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17895979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17897980
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17899986
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17850378
Basically, the end result should be something like this:
mysqldump -uuser -ppassword --compact --no-create-info db table_name --where="id in (17900018,17900019,17900020...)" >> dump.sql
It takes 2000 IDs at a time adds them to dump.sql and then goes to the next 2000 until all the IDs are read from the file.
With echo command to display output, I get the following:
)17853963ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17851964
)17855964ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17853964
)17857964ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17855965
)17859972ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17857965
)17861975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17859973
)17863975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17861976
)17865975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17863976
)17867975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17865976
)17869975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17867976
)17871975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17869976
)17873976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17871976
)17875976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17873977
)17877976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17875977
)17879976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17877977
)17881976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17879977
)17883976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17881977
)17885976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17883977
)17887976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17885977
)17889976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17887977
)17891976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17889977
)17893976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17891977
)17895976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17893977
)17897977ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17895977
)17899983ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17897978
)17850375ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17899984
17900027)mp -uuser -ppassword --compact --no-create-info db table_name --where=id in (17850376
)17853963ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17851964
)17855964ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17853964
)17857964ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17855965
)17859972ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17857965
)17861975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17859973
)17863975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17861976
)17865975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17863976
)17867975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17865976
)17869975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17867976
)17871975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17869976
)17873976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17871976
)17875976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17873977
)17877976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17875977
)17879976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17877977
)17881976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17879977
)17883976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17881977
)17885976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17883977
)17887976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17885977
)17889976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17887977
)17891976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17889977
)17893976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17891977
)17895976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17893977
)17897977ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17895977
)17899983ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17897978
)17850375ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17899984
17900027)mp -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17850376
2
Answers
NOTES:
rn
) in the input file (id_list
)r
characters the next issue will likely be an invalidin()
list … which is what this answer will focus on …Sample input file:
Modified
xargs
call:Adding
echo
to see what the current code is generating:NOTES:
bash
so I’ve replacedsh -c
withbash -c
--where/in()
clause--where/in()
clauseOne idea for addressing these issues:
I have a different way of approaching to this problem (without
xargs
).I tried to re-create your scenario and it is working for me.
Have a look below.
Generating Sample file for Ids:
The Code:
The Output:
I was able to successfully take the dump with this. The numbers in the output are nothing but
echo "${filecount}"
from the above script.Note:
I would recommend to make a copy of your
id_list
file before proceeding with this approach, since we are removing ids from the file for which backup is taken. (For me it was just a sample self-generated file)