Admin Life Errors, Fixes, and Encounters

8Jan/101

mysql large database dump

If you have a large database dump and you need to edit the .sql dump file but can't seem to load it into memory. Here is what I've done.

#cat file, replace string and save file
#good to change the dbname in an sql 22GB file
cat large_db_dump.sql | sed -e 's/db_name1/db_name1_backup/' > large_db_dump.new.sql

-------------
#exclude a table from a mysql dump file
cat large_db_dump.sql | grep -v 'INSERT INTO `bad_table`' > large_db_dump.new.sql

#or you can do it from mysql while you export

#dump db without a table
mysqldump -u root -p --ignore-table=large_db_dump.bad_table > large_db_dump.sql

#backup a single table
mysqldump -u root -p -hlocalhost large_db_dump good_table > large_db_dump.good_table.sql

Filed under: commands, Unix 1 Comment
8Jan/100

unix find tips & tricks

How to search for a string in a selection of files (-exec grep ...).
find . -exec grep "text_here" '{}' \; -print

How to search for a string in a type of file
find . -name "*.php" -exec grep "text_here" '{}' \; -print

How to find a string with in files that have been modified during the specified time interval
# -ctime time interval Locates files that that were created during the specified time interval
# -mtime time interval Finds files that have been modified during the specified time interval
# -atime time interval Locates files that have been accessed during the specified time interval
find . -mtime -10 -exec grep "javascript" '{}' \; -print | more

#list files over 2 days old (good idea before you delete)
find . -type f -mtime +2 -exec grep "" '{}' \; -print

#delete files over 2 days old
find . -type f -ctime +2 -exec rm -f {} \;

#copy from the current folder to folder_b that have been changed within the last 15 days.
#How do I selectively copy files from a directory structure?
find . -name "*" -mtime -15 -print | cpio -pavd /folder_b/

Filed under: commands No Comments