Synchronizing Folders using Rsync

This is an alternative to the “mv” command (move) or cp (copy) but slightly with a added feature of doing it remotely from server to another server.

Local Server
rsync -avzp /source-address/* /destination-address/

Remote Server
rsync -avzp -e ‘ssh -p portnumber’ /source-address/* root@ipaddress:/destination-address/

source-address = the source of the folder/files eg:

destination-address = the destination to sync the files from the source eg:

portnumber = the ssh port number, default is:

ipaddress = the ip address of the destination server of the hosname eg: or

Lastly, don’t forget to change the file ownership, example like below:
chown username.username *

================== Edit 1 ===================

If you noticed, some files won’t be copied over using the Rsync, especially like the .htaccess file. As an alternative you can use this coding to copy those special file like example below:
scp -P portnumber /home/username/public_html/.htaccess root@ipaddress:/home/username/public_html/

If a folder that can’t be transfered, you can use as below, but make sure to create a folder at server B also, for example as below:
scp -P portnumber /home/username/public_html/.smileys/* root@ipaddress:/home/username/public_html/.smileys/

Don’t forget to change the ownership again.

================== Edit 2 ===================

When moving website that have a database, make sure to properly configure the data base when transferring it.

Let say now our current situation, server A is transferring to server B. After the files have been transferred to server B, log into server A PhpMyAdmin and find the account name.

Click to open the database (_testdb).

Click Export
Select compression = gzipped
Click Go

Then just save it any place in your pc.

Ok then, next is a bit tricky part. Go to server B, and the folder where you upload the file and try to open:
nano configuration.php

The content of the file as below:
$mosConfig_offline = ‘0’;
$mosConfig_host = ‘localhost’;
$mosConfig_user = ‘username_testdb’;
$mosConfig_password = ‘xxxxx’;
$mosConfig_db = ‘username_testdb’;

$mosConfig_dbprefix = ‘mos_’;
$mosConfig_absolute_path = ‘/home/username/public_html/’;
$mosConfig_live_site = ‘’;
$mosConfig_sitename = ‘Testing Website’;
$mosConfig_shownoauth = ‘0’;
$mosConfig_useractivation = ‘1’;
$mosConfig_uniquemail = ‘1’;
$mosConfig_usecaptcha = ‘0’;
$mosConfig_offline_message = ‘This site is down for maintenance.<br /> Please check back again soon.’;
$mosConfig_error_message = ‘This site is temporarily unavailable.<br /> Please notify the System Administrator’;
$mosConfig_debug = ‘0’;
$mosConfig_lifetime = ‘900’;
$mosConfig_MetaDesc = ‘This Software Site Is Under Serverfreak’;
$mosConfig_MetaKeys = ”;
$mosConfig_MetaAuthor = ‘1’;
$mosConfig_MetaTitle = ‘1’;
$mosConfig_lang = ‘english’;
$mosConfig_locale = ‘en’;
$mosConfig_charset = ‘utf-8’;
$mosConfig_locale_debug = ‘0’;
$mosConfig_locale_use_gettext = ‘0’;
$mosConfig_offset = ‘0’;
$mosConfig_hideAuthor = ‘1’;
$mosConfig_hideCreateDate = ‘1’;
$mosConfig_hideModifyDate = ‘1’;
$mosConfig_hidePdf = ‘0’;
$mosConfig_hidePrint = ‘0’;
$mosConfig_hideEmail = ‘0’;
$mosConfig_enable_log_items = ‘0’;
$mosConfig_enable_log_searches = ‘0’;
$mosConfig_enable_stats = ‘0’;
$mosConfig_sef = ‘0’;
$mosConfig_vote = ‘0’;
$mosConfig_gzip = ‘0’;
$mosConfig_multipage_toc = ‘1’;
$mosConfig_allowUserRegistration = ‘0’;
$mosConfig_link_titles = ‘0’;
$mosConfig_error_reporting = ‘-1’;
$mosConfig_register_globals = ‘1’;
$mosConfig_list_limit = ’50’;
$mosConfig_caching = ‘0’;
$mosConfig_cachepath = ‘/home/username/public_html/cache’;
$mosConfig_cachetime = ‘900’;
$mosConfig_mailer = ‘mail’;
$mosConfig_mailfrom = ‘[email protected]’;
$mosConfig_fromname = ”;
$mosConfig_sendmail = ‘/usr/sbin/sendmail’;
$mosConfig_smtpauth = ‘0’;
$mosConfig_smtpuser = ”;
$mosConfig_smtppass = ”;
$mosConfig_smtphost = ‘localhost’;
$mosConfig_back_button = ‘0’;
$mosConfig_item_navigation = ‘0’;
$mosConfig_secret = ‘xxxxxx’;
$mosConfig_pagetitles = ‘1’;
$mosConfig_readmore = ‘1’;
$mosConfig_hits = ‘1’;
$mosConfig_icons = ‘1’;
$mosConfig_favicon = ‘favicon.ico’;
$mosConfig_fileperms = ”;
$mosConfig_dirperms = ”;
$mosConfig_mbf_content = ‘0’;
$mosConfig_helpurl = ‘’;

The parts I bold above are the part you need to pay attention.
$mosConfig_user = ‘username_testdb’;
$mosConfig_password = ‘xxxxx’;
$mosConfig_db = ‘username_testdb’;
$mosConfig_absolute_path = ‘/home/username/public_html/’;
$mosConfig_cachepath = ‘/home/username/public_html/cache’;

So now assuming that our database name and the user is username_testdb, while the password is xxxxx

Go to the the account’s cPanel. Under Database, select the MySQL Databases. Under Create New Database, fill in the BOLD part as below:
New Database:   username_testdb
and then click the Create Database button.

Next, go to the Add New User, then fill in as below:
Password (Again):xxxxx
Click Create User button afterward.

Then, go to Add User To Database section, select as below:
User: username_testdb
Database: username_testdb
and click on the Add button.
It will bring to a new page. This page is quite important. Make sure to Tick the ALL PRIVILEGES checkbox and then click the Make Changes button.

==================== End ====================

Ok then, the database part is finished. Make sure to test run and check whether got any error message or not. By the way, this were all tested in a cPanel-based hosting. The Rsync and the scp part will work on any hosting, but the database part might be slightly different.

Happy Trails.

Leave a Reply