Skip to main content

Posts

Showing posts with the label Unix

Use rsync command over ssh to to take backup of files.

Today we are going to discuss over "how to use rsync command over ssh to take backup of files" . Before that let's know little bit about rsync itself. rsync :   rsync is a little Linux utility that synchronizes filesystems from one place to another by only copying diffs (deltas) of files that have changed. rsync optionally compresses the files ont-the-fly before transfer (to save transfer time) and may be used in conjunction with rsh or ssh to perform remote file transfers. rsync may be used as a backup or mirroring utility. The advantage of using rsync over other archive and copy utilities such as tar, dump and rcp are: (1) rsync can use ssh as a secure channel to transfer files over the network. (2) It provides an ability to retain ownership and permission of files being transferred. (3) It enables files and directories to be synchronized (deleted files are deleted from the last replication), and  (4) transfers only "delta" ...

Shell Script to export MySQL table data into a text file

Hi, our today's topic is " Write Shell Script to export MySql table data into a text file ". I will try my best to explain each and everything in steps. Let's start : Following is full shell script #tableexport.sh   #(1) define variables DBNAME=test FNAME=/usr/tmp/$(date +%Y.%m.%d)-$1.txt #(2)creates an file with column names seperated by comma in a single line mysql -u$2 -p$3 $DBNAME -B -e "SELECT COLUMN_NAME FROM information_schema.COLUMNS C WHERE table_name = '$1';" | awk '{print $1}' | grep -iv ^COLUMN_NAME$ | sed 's/^/"/g;s/$/"/g' | tr '\n' ',' > $FNAME #(3)appends newline to mark beginning of data vs. column titles echo "" >> $FNAME #(4)dumps data from DB into /usr/tmp/tempfile.txt mysql -u$2 -p$3 $DBNAME -B -e "SELECT * INTO OUTFILE '/usr/tmp/tempfile.txt' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' FROM $1;...