顯示具有 unix 標籤的文章。 顯示所有文章
顯示具有 unix 標籤的文章。 顯示所有文章

2009年6月15日 星期一

MySQL Backup and Recovery with Command-Line

the mysqldump client is a backup program which can be used to dump a database or a collection of databases for backup or transfer to another sql server. the dump typically contains sql statements to create the table, populate it, or both.

backup an entire database

mysqldump -u username -p db_name > backup.sql

-p, --password
-u, --user=username

backup a table

mysqldump db_name table > backup.sql

dump several databases with one command

mysqldump --databse db_name1 db_name2 .. > databases.sql

dump all databases

mysqldump --all-databases > all_databases.sql



you need to create the databases manually if your target mysql server has no database with same name before recovery

mysql> create database db_name;

restore

mysql -u username -p < backup.sql

2008年11月2日 星期日

Surface and Bad Blocks check of Hard Disk on Unix

1. unmount the device you want to check

umount /dev/sda1

2. search the device for bad blocks

# -s: show the progress of the scan
# -v: verbose mode

badblocks -sv /dev/sda1

--
create a filesystem that excludes the badblocks which have been checked

mke2fs -c /dev/sda1

2008年10月2日 星期四

Creat filesystem index for searhing purpose on Unix

if there are no updatedb and locate commands available, this is an alternative method on any unix-like os

1. using find to produce a list of all files' name and path

find / > fsindex

2. search for file

grep keyword fsindex

2008年7月29日 星期二

3 methods to read text file line by line as variable in shell script of Unix

1.

while read var
do
..$var..
done < FILE

2.

cat FILE |
while read var
do
..$var..
done

3.

for var in `cat FILE`
do
..$var..
done

2008年4月23日 星期三

How to Secure Copy on Unix

upload

scp filename username@ip:path/new_filename

download

scp username@ip:path/filename new_filename

parameter

-v toggle verbose