Archive for the ‘Debian’ Category

Backup and restore mysql databases on the shell

Thursday, August 13, 2009 posted by admin

One way to create a backup of a mysql database on the shell is to use the mysqldump command. Mysqldump creates a dump of the database in form of sql commands.

Backup

mysqldump -u root -p mydatabase > /tmp/backup_mydatabase.sql

This command creates a backup of the database with the name “mydatabase” in the file /tmp/backup_mydatabase.sql

Restore

To restore the backup, use the command:

mysql -u root -p mydatabase < /tmp/backup_mydatabase.sql

To get detailed information on the CPU, use this command:

cat /proc/cpuinfo

The output will look similar to this:

cat /proc/cpuinfo
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 15
model           : 107
model name      : AMD Athlon(tm) 64 X2 Dual Core Processor 5600+
stepping        : 2
cpu MHz         : 2900.171
cache size      : 512 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 2
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 1
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm cr8legacy ts fid vid ttp tm stc [6]
bogomips        : 5945.45

Get detailted information on memory usage:

cat /proc/meminfo

MemTotal:      4116112 kB
MemFree:        470164 kB
Buffers:        154592 kB
Cached:        1658332 kB
SwapCached:        488 kB
Active:        2304500 kB
Inactive:      1017644 kB
HighTotal:     3243840 kB
HighFree:       183672 kB
LowTotal:       872272 kB
LowFree:        286492 kB
SwapTotal:     4200888 kB
SwapFree:      4197128 kB
Dirty:            4764 kB
Writeback:           0 kB
AnonPages:     1378960 kB
Mapped:         135580 kB
Slab:           289720 kB
PageTables:      16680 kB
NFS_Unstable:        0 kB
Bounce:              0 kB
CommitLimit:   6258944 kB
Committed_AS: 3779921956 kB
VmallocTotal:   118776 kB
VmallocUsed:     11892 kB
VmallocChunk:   106628 kB

Information about disk usage

df -h

df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/md2              375G   41G  315G  12% /
tmpfs                 2.0G     0  2.0G   0% /lib/init/rw
udev                   10M   52K   10M   1% /dev
tmpfs                 2.0G     0  2.0G   0% /dev/shm
/dev/md1              510M   37M  448M   8% /boot

And the partitions:

fdisk -l

Disk /dev/sda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000d6430

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1       10255    82373256   83  Linux
/dev/sda2           10256       10443     1510110    5  Extended
/dev/sda5           10256       10443     1510078+  82  Linux swap / Solaris

Linux: How to view log files on the shell?

Saturday, August 8, 2009 posted by Till

Many linux servers are administered on the commandline e.g. with a SSH connection. In the following article, I will explain several shell commands that make it easy to view logfiles.

The most important command is “tail”. Tail can be used to read the last lines from a file. Examples:

Get the last 100 lines from the Debian mail log file:

tail -n 100 /var/log/mail.log

To get all newly added lines from a log file in realtime on the shell, use the command:

tail -f /var/log/mail.log

to quit tail and go back to the commanline press the keys [ctrl] + [c]

If you want to get the last 1000 lines from a log file and they do not fit into your shell window, you can use the command “more” to be able to view them line by line.

tail -n 1000 /var/log/mail.log | more

press [space] to go to the next line or [ctrl] + [c] to quit.

If you want to search for a specific term in a large file, the command “grep” comes in handy. Example: We search for the email address “tom@anydomain.tld” in the mail log file:

grep “tom@anydomain.tld” /var/log/mail.log

If you want to view the whole content of file on the shell, use the command “cat”. Example:

cat /proc/cpuinfo

will show you detailed info about the CPU of your computer.

If you experience problems with slow logins in pure-ftpd, this is often caused by a problem with the resolving of the clients hsotname. This happens e.g. when you run a FTP server in your intranet and the hostname of the client computer does not exist in DNS. To disable name resolving in pureftpd, run the command:

echo ‘yes’ > /etc/pure-ftpd/conf/DontResolve

and then restart pure-ftpd

/etc/init.d/pure-ftpd-mysql restart

Disabling name resolving also fixes the following error message:

Jul 24 16:26:28 ispconfig pure-ftpd: (?@?) [ERROR] Sorry, invalid address given

This articles describes the renewal of SSL certificates for courier pop3 and imap server. This is nescessary e.g. when the certificates are expired or contain the wrong hostname.

First delete the exsiting certificates:

rm -f /etc/courier/imapd.pem
rm -f /etc/courier/pop3d.pem

Then edit the template that contains the details for the ecrtificates so that the hostname in the certificate matches the hsotanme of your server and that the email address matches your postmaster email address:

vi /etc/courier/imapd.cnf
vi /etc/courier/pop3d.cnf

and create the new certificates:

mkimapdcert
mkpop3dcert

Courier pop3 and imap have to be restarted so they pick up the new ecrtificates:

/etc/init.d/courier-imap-ssl restart
/etc/init.d/courier-pop-ssl restart

To turn on verbose logging (e.g. to debug FTP connection or authentication problems) in  pure-ftpd FTP server on Debian and Ubuntu Linux, execute the following command as root user in the shell:

echo 'yes' > /etc/pure-ftpd/conf/VerboseLog

and then restart pure-ftpd

/etc/init.d/pure-ftpd-mysql restart

The debug output will be logged to syslog. To view the log content, execute:

tail -n 100 /var/log/syslog

To disable verbose logging, execute these commands:

rm -f /etc/pure-ftpd/conf/VerboseLog
/etc/init.d/pure-ftpd-mysql restart