CentOS website backup shell scripts

It’s vitally important to backup your website on another machine. If you have a website running on a machines and have a FTP account on another server or even a computer at your home, Follow this step-by-step guide, you will be setting up a reliable automatic regular backup.

Step 1: SSH to your VPS console and install lftp

yum install lftp

Step 2: Create a folder on your ftp server that will hold the backup files.

Step 3: Edit the following script and unload it to your VPS, for example, /root/backup.sh

You will need to set the values like your root mysql account and ftp account, web folder to backup.


#!/bin/bash
#Author: licess
#Website: http://lnmp.org

#IMPORTANT!!!Please Setting the following Values!

######~Set Directory you want to backup~######
#website dir under /home/web
$www_base_dir = /home/web
$local_backup_dir = /home/backup/out

Backup_Dir1=xxx.com

######~Set MySQL UserName and password~######
MYSQL_UserName=root
MYSQL_PassWord=your_root_password

######~Set MySQL Database you want to backup~######

Backup_Database_Name1=_database_to_backup
#Uncomment these if you have more databases to backup
#Backup_Database_Name2=_gt4tcn
#Backup_Database_Name3=_dallascaoen
#Backup_Database_Name4=_dallascaocn

######~Set FTP Information~######
#setup your FTP where you backup your websites to
FTP_HostName1=hostname_or_IP
FTP_UserName1=FTP_username
FTP_PassWord1=FTP_password
#you need to create dir on your ftp first.
FTP_BackupDir1=/backup_dir/

#Values Setting END!

#TodayWWWBackup=www-*-$(date +"%Y%m%d").tar.gz
#* is wildcard.
TodayDBBackup=db-*-$(date +"%Y%m%d").sql
OldWWWBackup=www-*-$(date -d -3day +"%Y%m%d").tar.gz
OldDBBackup=db-*-$(date -d -3day +"%Y%m%d").sql

tar zcf /home/backup/www-$Backup_Dir1-$(date +"%Y%m%d").tar.gz -C $www_dir $Backup_Dir1 --exclude=soft

/usr/local/mysql/bin/mysqldump -u$MYSQL_UserName -p$MYSQL_PassWord $Backup_Database_Name1 > $local_backup_dir/db-$Backup_Database_Name1-$(date +"%Y%m%d").sql
/usr/local/mysql/bin/mysqldump -u$MYSQL_UserName -p$MYSQL_PassWord $Backup_Database_Name2 > $local_backup_dir/db-$Backup_Database_Name2-$(date +"%Y%m%d").sql
/usr/local/mysql/bin/mysqldump -u$MYSQL_UserName -p$MYSQL_PassWord $Backup_Database_Name3 > $local_backup_dir/db-$Backup_Database_Name3-$(date +"%Y%m%d").sql
/usr/local/mysql/bin/mysqldump -u$MYSQL_UserName -p$MYSQL_PassWord $Backup_Database_Name4 > $local_backup_dir/db-$Backup_Database_Name4-$(date +"%Y%m%d").sql

#will delete multiple files db-*-$(date +"%Y%m%d").sql
rm -f $local_backup_dir$OldWWWBackup
rm -f $local_backup_dir$OldDBBackup

cd $local_backup_dir

lftp $FTP_HostName1 -u $FTP_UserName1,$FTP_PassWord1 << EOF
cd $FTP_BackupDir1
mrm $OldDBBackup
mput $TodayDBBackup
bye
EOF
#mput $TodayWWWBackup

4. Test out the script to see if it works as expected. You shall have files like www-xxxx-20120101-tar.gz and db-xxxx-20120101.sql on both your local backup dir and remote ftp backup dir.

Also notice that the script will delete backup files 3 days old.

5. Setup a crontab entry to make this script run automatically everyday.

crontab -e

Enter:
0 0 * * * bash /root/backup.sh

Save the file and exit.

Share

Quick solution to Pureftpd 553 error

After setting up an account with Pureftpd, you are likely to be greeted by an error 553:

Pureftpd error 553 Can't open that file: Permission denied

It has to do with the user and group permission. Solution:

1. Edit your Pure-ftpd account and set UID and GID to www (or any other).
2. SSH to root console. and run
chown -R www:www /home/backup

Replace “/home/backup” with your ftp folder. This command assigns userid www, usergroup www to be the the owner of that folder and all the folder underneath it (R = recursive)

Share

Solve “Specified key was too long; max key length is 1000 bytes” error when installing postfixadmin

Go to the folder where postfixadmin is extracted. Edit “upgrade.php”

Replace all “255″ with “100″

Done!

Share

Step by step LNMP installation guide for CentoOS servers

Believe me: Installing the LNMP one-key package is the easiest and most time-saving way to set up a production CentoOS server. After installation, your server will installed with Nginx, PHP, MySQL, phpMyAdmin, Zend and ready to serve.

LNMP one-key package is a bunch of shell scripts that automate the installation of Nginx, PHP and MySQL server production environment. It’s written by Licess.
Please follow the steps carefully and leave a comment when in doubt.

To make the narrative easier, let’s suppose that you have a domain name: www.lovelyoldies.com that points to your server’s IP 199.180.252.249 . For easier administration, set up a second level domain name admin.lovelyoldies.com and point it to 199.180.252.249 too.

Connect to your VPS console using your root account (using Putty, Tunnelier, etc):

1. Create a temp directory under root if it is not there and go to that directory. This is where you will put the installation files.

mkdir /root/temp
cd /root/temp

2. Download the lnmp package and unpack and then enter the unpacked directory.

wget -c http://soft.vpser.net/lnmp/lnmp0.8.tar.gz
tar zxvf lnmp0.8.tar.gz
cd lnmp0.8/

3. Run the installation

./centos.sh

You will be prompted to enter a domain name. DO NOT enter your domain name that will be used for you site. In our example, enter admin.lovelyoldies.com or the IP address 199.180.252.249.
You will be prompted to enter a password for mysql root user. Enter a password and write it down. You will be using the user name root together with this password to log on to phpmyadmin.
Now, stand up from your computer and chat to your wife or play with your children. It’s going to take a while. During this time Nginx, PHP, MySQL, phpMyAdmin, Zend will be installed.

After installation finishes, open http://admin.lovelyoldies.com with your web browser. A congratulation page appears (Sorry, it’s in Chinese).

All done! Bye!!

Wait… you will say…
If the congratulation page doesn’t appear, it means:

If you just set up the DNS record for your domain name, it’s going to take a while for it to point to the right IP. Of course, you don’t want to wait. Let’s make it effective immediately. Skip step four if your domain name is already pointed to the right IP.

4. If you are using Windows, go to C:\Windows\System32\drivers\etc and find the the file named “hosts” and open it with notepad. Add

199.180.252.249 lovelyoldies.com
199.180.252.249 www.lovelyoldies.com
199.180.252.249 admin.lovelyoldies.com

5. Now,the PHP and Ngix that has been installed is not the newest version. You may want to update them for security reasons. Run (you are now at /root/temp/lnmp0.8/):


./upgrade_nginx.sh

Enter the version number you want to upgrade to when prompted. Go to http://nginx.org/ to find available versions.


./upgrade_php.sh

Enter the version number you want to upgrade to when prompted. Go to http://php.net/ to find available versions.

6. Create a folder where you would like to upload your site. In our example, /home/web/lovelyoldies.com/


mkdir /home/web/lovelyoldies.com

7. Now we want our domain names to be tied to this folder. run:

/root/vhost.sh

Enter your domain name as prompted: lovelyoldies.com.
Then you are asked:”do you want to add more domain name?” Press y
Enter www.lovelyoldies.com as we want these two domain names to be the same site.
The you will be prompted: “Enter the directory name for the domain names” (something like this, you won’t miss it.)
Enter /home/web/lovelyoldies.com

8. Use your SFTP client (Tunnelier, FileZilla, etc) and upload your website to /home/web/lovelyoldies.com
All done! open http://lovelyoldies.com with your web browser! Bye

Wait… you will yell:-)

9. If you are installing a new wordpress site, you will need to go to (in our example):
http://admin.lovelyoldies.com/phpmyadmin

Log on using root and your root password (see step 3) for mySQL and create a database and optionally assign a user to that database.

Then run the wordpress installation.

You are likely to meet more issues like setting up SSL, url rewriting… (if you need these) but I am going stop here.

Bye…

Share

GT4T: a different approach to MT

GT4T takes a rather different approach to MT:

The result is often disappointing when sending the whole segment to MT. With GT4T you can select any portion of a sentence. GT4T aims to incorporate MT into the translation process, helping translators with suggestions and reducing keystrokes, rather than using MT as a first draft translator.

Show alternative translations for every syntagm. It’s exciting as you have many possible translations for each part of a sentence. It works very well when you mind gets stuck or tired.

Show both Google and Bing translations.

A combination of User-defined Glossary and MT. When MT cannot translate a term correctly, you can add it to Glossary and then result is always correct.

Share