Aug 23

linux — how to exclude directory or files when bakup with rsync

rsync has been heavily used in server daily backup.I am not going to list all option of rsync. i just don’t want to backup some useless file such as cache and log file.

In a typical backup situation, you might want to exclude one or more files (or directories) from the backup. You might also want to exclude a specific file type from rsync.

To exclude a special directory,take a look at the command below:

Source code    
rsync -avze 'ssh -p7788' --exclude 'dir_abc'  /home/www  root@ip:/home/bak/

This command will not sync the /home/www/dir_abc

You can use * to match multiple directory to exclude like this:

Source code    
rsync -avze 'ssh -p7788' --exclude 'dir_*'  /home/www  root@ip:/home/bak/

You can also use multiple –exclude option to exclude:

Source code    
rsync -avze 'ssh -p7788' --exclude 'dir_abc' --exclude 'webcache' --exclude '*.log' /home/www  root@ip:/home/bak/

Keep in mind that rsync will always treat the value of the –exclude option as relative to the bakup dir even though you specified a absolute path,so

if there is a dir1 directory in /home/www

Source code    
rsync -avze --exclude '/home/www/dir1' /home/www /home/bak

rsync will explain /home/www/dir1 as /home/www/home/www/dir1,but this is not what you want.when you specified the path for –exclude option,make sure it’s relative to the source data diretory.this action will not be affected by add / to the exclude path.

Aug 21

linux — use public key authentication to log into ssh

what to do if you want to automate run rsync over ssh without specify any password to backup data?well the only way to access remote ssh server without password is to use pubkey authentication.

First,on the ssh server you need to login,config it to accept pubkey authentication:

vi /etc/ssh/sshd_config

comment out the line PubkeyAuthentication yes and restart sshd dameon:

/etc/init.d/sshd restart

Second, go to the client server,the one you need to bakup.issue the command ssh-keygen to generate a public and private keypair:

# ssh-keygen

press enter without setting any passphrase,.Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub. Copy the content of id_rsa.pub file and paste it to the backup user’s authorized_keys file on the ssh server. if the you use root user,then you need to stored the pub key to /root/.ssh/authorized_keys.This file store all authorized keys for all clients,each line for each client server.It looks like

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAtjz9QhNQQAqDB/KoiiPLdI2aYyWWuw5QCRqsv+JmdWqWxWivfxCnG+LXw9V/jBpvGFCW4wCwIlO0pq/HGMfts2rjCElWvaeZiDuIwR38TCVbPDzl670MRcWjvp+Gy3IIkrkI7J419VNeCEuGria5t4THdHI4Gsz21nSUbFyko5E= rsa-key-20120510

Third, now you can rsync via ssh without specify ssh password for the user.ie

rsync -avze ‘ ssh -p9998 ‘/home/www/abc.com  root@ip:~/bak

Aug 19

javascript — open lots of urls in new tab

Sometimes,i need to open a lot of url to finish some work.so i need a javascript code to save time.i can run them from firebug console.

Source code    
var domains = ['url1','url2','url3'];
for(i in domains) {
    window.open(domains[i]);
}

The url to assign main shared ip to a reseller acct in WHM:

/cpsess3712993106/scripts2/dodelegatemainip?mainip=212.117.179.142&user=share033

The url to change ip of a domain/acct

/cpsess3808654605/scripts2/changeip?oldip=212.117.179.90&customip=212.117.179.96&user=airjoruk

 

Aug 18

zen cart — recover zen cart database from mysql data folder

One of my server crashed last week. They do a hard disk rescue and i only get a copy of the mysql data folder(the physical data file of all databases).The new server is ready for use,with the mysql and cpanel updated.so i got no lucky to recover with copy the mysql folder back to the new mysql data folder.it only show the database without any table.

i found i do have a mysqldump backup on 2012 -05 -24.but the lates data(2012-08-09) was stored as mysql physical data file,not sql.how to recover all the zen cart databases with the latest data?is it possible.

There is two way to try:

The first one is to install anthoer copy of mysql.it must be same version as the one before system crashed.and same /etc/my.cnf. The you can turn off the currently running mysql ,copy the the mysql data folder to the data folder of the the old copy mysql.Start the mysql and mysqldump to backup all the zen cart database. The switch mysql to the latest mysql,import all databases;

Sometimes it’s impossible to achive the last version of mysql with same configuration.The what can we do?You can mysqldump the database schema(only structure) from a zen cart database with following command:

mysqldump –no-data zencartdb > onlyschema.sql -u root -p’password’

Then create all the databases you want to recover and import the zen cart database schema to every zen cart database.

mysqladmin create database1 -u root -p’password’

mysql database1 < onlyschema.sql -u root -p’password’

Now turn of mysql dameon process to unlock all databases and tables(if exist).copy the data folder bakup to the mysql data folder.

/etc/init.d/mysqld stop
cp -Rf  /home/bak/mysql/*  /var/lib/mysql/

And all is done. However,keep in mind if you use INNODB storage engine in your old mysql database,then the recovery may be more complicated.

Aug 17

linux — fdisk and makefs.ext3 to partition and format a new disk

To show a list for disk intalled on your server,you can issue the command below:

Source code    
fdisk -l | grep '^Disk'

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
Disk identifier: 0x0004d76c
Disk /dev/sdb: 1500.3 GB, 1500301910016 bytes
Disk identifier: 0x00065d74
Disk /dev/sdc: 1500.3 GB, 1500301910016 bytes
Disk identifier: 0x27b927b8

it shows my server has tree disk;Now let’s start to partion the second disk /dev/sdb,

Source code    
fdisk /dev/sdb

This command will switch you from shell to fdisk console,issue the m command fdisk will print all the available command.Below is a summary of the fdisk command:

  • m – print help
  • p – print the partition table
  • n – create a new partition
  • d – delete a partition
  • q – quit without saving changes
  • w - write the new partition table and exit

With those command, the new disk can be easily cut into any partitions.After partition,you need to format the newly created partition so it can be mounted.

Source code    
mkfs.ext3 /dev/sdb1

Then you can mount the partition as below:

Source code    
# mkdir /sdb1
# mount /dev/sdb1 /sdb1

To make the /dev/sdb1 partition be mounted after system reboot,you need to update /etc/fstab file as below:

Source code    
/dev/sdb1     /sdb1       ext3    defaults      1 2

or you can label the partition using e2label. For example, if you want to label the new partition /backup, enter

e2label /dev/sdb1 /backup

Then You can use label name insted of partition name to mount disk using /etc/fstab:

LABEL=/backup /sdb1 ext3 defaults 1 2

Aug 16

WHM — How to create acct from command line

how to create a whm reseller acct and assign a domain?WHM/Cpanel comes with a lot of script located in /script  directory. The /script/wwwacct can be usefull to create acct from ssh. So to create a new acct,we need to take a look at its syntax,run the command below from ssh:

/script/wwwacct

It will print:

Please use the this syntax
wwwacct <domain> <user> <pass> <quota> <cpmod[advanced/?]> <ip[y/n]> <cgi[y/n]> <frontpage[y/n]> <maxftp> <maxsql> <maxpop> <maxlst> <maxsub> <bwlimit> <hasshell[y]/[n]> <owner> <plan> <maxpark> <maxaddon> <featurelist> <contactemail> <use_registered_nameservers> <language>

So,we need to supply domain,user ,pass etc,for example,

/scripts/wwwacct abcd.com abcd  ‘password’  0 x3 y y y 0 0 0 0 0 0 n root 0 0 0 ” ” 0 en

This can be very usefull if you need to create a lot of new acct. The drawback is that we need to confirm for every acct.The comfirmation may can be bypassed  with sleep and echo command.

Aug 15

msyql — msyqldump only dump the database schema

mysqldump can dump whole database including both data and its schema(structure).what if you only need to make a backup of the database schema.To backup only the database structure,you can use the following msyqldump command line option –no-data,for example:

Source code    
msyqldump -u root -p --no-51&q=DATA&lr=lang_en">data database1 > db_schema.sql

This will only do a backup of structure of the database database1.

Aug 13

mysql -MySQL root password in DirectAdmin

If you got a server running DirectAdmin without mysql root info. how to get root access to mysql. In fact,mysql root password is set within the DirectAdmin installation process and written down to setup.txt(usually located in /usr/local/directadmin/scripts/setup.txt). If you didn’t change this password you can find the default one in the setup.txt, use the command below to see the contents of this file:
less /usr/local/directadmin/scripts/setup.txt

your password is stored in the line starting with mysql=

If you want to access mysql from ssh or console directly create a file in /root/ dir called .my.cnf:

touch /root/.my.cnf

and edit this file with the vi editor:

vi /root/.my.cnf

Add the lines below:

[client]
user=root
password=XXXXXX

Fill the password with the pass you got from setup.txt, save the file with SHIFT+ZZ or :wq and exit. After this step just write mysql to enter MySQL console directly without password.
[root@test ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 169833
Server version: 5.0.77-log MySQL Community Edition (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql>

Aug 12

mysql — create database with mysql client command line option

mysql client is powerful with its shell like console.what about to create database or mysql user from command line option if you don’t want to log into mysql console.the mysql -e option can help with this.To create database , we can issue the following command:

mysql -u mysql_user -p mysql_pass -e “CREATE DATABASE db1;”

To create mysql user from command line option -e:

mysql -u mysql_user -p mysql_pass -e “GRANT ALL PRIVILEGES ON db1.* TO ‘db1_user’@'localhost’ IDENTIFIED BY ‘db1_pass’;”

with the help of -e option,we can batch create database and mysql user in our script.i think that’s why mysql client program support this option.

Aug 10

zen cart — how to turn of ezPages header links bar

if you don’t want to ezPages links to show on the header bar or footer bar?how to remove or disable them?

In the admin control panel go to Configuration –> EZ-Pages Settings to turn them off.Click on EZ-Pages Display Status -HeaderBar and change the setting to 0.This will turn off the link bar in the header.
The same applies for the Footer Bar and Side box links!