Category Archives: Server Implement

DB backup restore command line

Backup

mysqldump -u dbuser -p db_name | gzip -9 > db.sql.gz

Restore

New DB:
gunzip < db.sql.gz | mysql -u dbuser -p dbname
Existed DB:
mysqlimport -u dbuser -p dbname db.sql
// Sorry this version is not in compressed
Advertisements

Find files contains text Linux

find . -type f -exec grep -il "Text to find" {} \;

Bonus:  Search command in WinSCP

find . -type f -exec grep -il "!?prompt?!" {} \;

Backup and Restore in UBUNTU

Backup:
cd targetfolder
tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz ./

Backup with split

cd targetfolder
tar -cvpz backup.tar.gz --exclude=/backup.tar.gz ./ | split -d -b 3900m - ./backup.tar.gz. 

Export:

tar -xvpzf backup.tar.gz -C targetfolder

Export with concat:

cat *tar.gz* | tar -xvpzf - -C targetfolder

List all cron jobs by crontab in UBUNTU

Command line:

 for user in $(cut -f1 -d: /etc/passwd); do echo $user; crontab -u $user -l; done

View log files in Ubuntu Linux

Linux Log files and usage

=> /var/log/messages : General log messages

=> /var/log/boot : System boot log

=> /var/log/debug : Debugging log messages

=> /var/log/auth.log : User login and authentication logs

=> /var/log/daemon.log : Running services such as squid, ntpd and others log message to this file

=> /var/log/dmesg : Linux kernel ring buffer log

=> /var/log/dpkg.log : All binary package log includes package installation and other information

=> /var/log/faillog : User failed login log file

=> /var/log/kern.log : Kernel log file

=> /var/log/lpr.log : Printer log file

=> /var/log/mail.* : All mail server message log files

=> /var/log/mysql.* : MySQL server log file

=> /var/log/user.log : All userlevel logs

=> /var/log/xorg.0.log : X.org log file

=> /var/log/apache2/* : Apache web server log files directory

=> /var/log/lighttpd/* : Lighttpd web server log files directory

=> /var/log/fsck/* : fsck command log

=> /var/log/apport.log : Application crash report / log file

To view log files at shell prompt

Use tail, more, less and grep command.
tail -f /var/log/apport.log
more /var/log/xorg.0.log
cat /var/log/mysql.err
less /var/log/messages
grep -i fail /var/log/boot

View log files using GUI tools using the GNOME System Log Viewer

System Log Viewer is a graphical, menu-driven viewer that you can use to view and monitor your system logs. System Log Viewer comes with a few functions that can help you manage your logs, including a calendar, log monitor and log statistics display. System Log Viewer is useful if you are new to system administration because it provides an easier, more user-friendly display of your logs than a text display of the log file. It is also useful for more experienced administrators, as it contains a calendar to help you locate trends and track problems, as well as a monitor to enable you to continuously monitor crucial logs.

You can start System Log Viewer in the following ways:

Click on System menu > Choose Administration > System Log:

(The GNOME System Log Viewer)

Note you can start the GNOME System Log Viewer from a shell prompt, by entering the following command:
$ gnome-system-log &

View log files in Ubuntu Linux


MD devices. Synching disks to backup in Ubuntu.

– Install mdadm easy by

apt-get install mdadm

– Change a disk to md format:

fdisk /dev/sdd
press "n" to create
press "t" to change format, choose "fd"

– Create a new synching disks. Paired:

mdadm –create –verbose /dev/md3 –level=1 –raid-devices=2 /dev/sdb1 /dev/sdd1

shutdown –r now

– Check all md devices:

cat /proc/mdstat

– Format

mkfs -t reiserfs /dev/md3

– View md device detail :

mdadm –detail /dev/md3

– Add device

mdadm –manage –add /dev/md3 /dev/sdd1

– Check disk’s status

fdisk -l | more

Ready to go? Let’s do it!!!

Oliver

del.icio.us Tags: ,,,


Mysql error log path Ubuntu

Well, when you trying to restart the mysql in Ubuntu:

/etc/init.d/mysql restart

… [fail] …

First, you find the error log path of Mysql.

/var/log/mysql.*

But, the final way to fix the MySQL error:

0. su –

1. # backup database files

cp -r /var/lib/mysql /var/lib/mysql.b

2. # remove app

aptitude purge mysql-server

3. # if you have another app:mysql-server-5.0

aptitude purge mysql-server-5.0

4. # reinstall

aptitude install mysql-server

5. # recopy files

cp -r /var/lib/mysql.b /var/lib/mysql

6. # restart mysql

/etc/init.d/mysql restart

You will see, it is faster than your fixing job.

 

*: If you get error when you remove, check the article "dpkg broken" in this blog.

del.icio.us Tags: ,,,,

Regards,

Oliver