How to change timezone on a Linux server (CentOS)

We run CentOS for many of our server builds and this question often comes up. Hope this helps.

Here are the steps:

  1. Make a backup copy of the default localtime file.
  2. [code]
    mv /etc/localtime /etc/localtime.bak

  3. Create a symbolic link to a new localtime file
  4. [code]
    ln -s /usr/share/zoneinfo/America/Los_Angeles /etc/localtime

Be sure to replace “America/Los_Angeles” with the directory (if your zone has one) and filename of the timezone you want to use. Then test your change by running the command “date” from the command line.

Use rsync to transfer files between Linux servers

We use rsync to transfer files across servers and to assist with a variety of tasks associated with backup and restore. We found this great tutorial over at Nixcraft. Check it out. They do a great job of explaining advanced uses of rsync.

In a nutshell, this is one of the most useful commands we use and thought we would share with you.

# copy files from server1(local) to server2

rsync -avz /var/www/html/*


How to backup to Amazon S3

## UPDATE 2017 ##
The method described below was in use 5 years ago. It may still work on your host, but there are more elegant ways to do this now. I keep it here for archive purposes only.

Need to backup your Linux server files and databases to Amazon S3? Here is a great tool –

Follow the install instructions.

Once you set up your S3 bucket, you can use this bash script to copy files to the S3 bucket:

## - file name =
## backup script to push archive files to Amazon S3 bucket
## 2012-01-04
# define where your backup files are stored locally on your server
# use s3cmd to upload files to S3 instance
s3cmd put FILENAME s3://BUCKET-NAME/
# email a note to yourself that backup is complete
mail -s "backup files and databases copied to S3"

Site Migration from Server1 to Server2: WordPress and Drupal friendly

This post was borne out of our mass migration to Rackspace. Naturally, it gets into some advanced, hairy stuff. However, when fully dialed in, this method can take less than 5 minutes, even for large WordPress or Drupal sites. In order to complete these tasks, you will need privileged shell access to both servers (including mysql access), you will need to have rsync installed and configured, and you will need DNS access to the destination server (server2).
* Note: The following steps contain some powerful commands. Please be careful! And don’t execute any command if, after reading the details, you are still unsure what will happen.

1. Export your MySQL Database using mysqldump. This is the only step that must be done while logged into server1.
More Details

1-2. Edit db_backup.sql. This only needs to be done if you plan to create a fully-functional development version of your site. Open db_backup.sql in your editor of choice. Find & Replace all old URLs ( to the new URLs ( Rename the .sql file & save it.

*Remaining steps will be done from server2.

2. Create a DNS entry for the site’s new home.

3. Establish the document root for your site’s new home – i.e. create the new site directory.
[code]user@server2:~$ mkdir /path/to/new_site_dir[/code]

4. Use rsync to migrate your site directory. Our example will transfer files from old_site_dir on server1 to new_site_dir on server2.
[code]user@server2:/path/to/new_site_dir$ rsync -avz user@server1:/path/to/old_site_dir/ .[/code]
More Details

4-2. Check owner/group of new directory. Be sure it is consistent with working sites.

5. Create MySQL database, database user, database password, and privileges.
[code]mysql> create database db_name; 
mysql> create user db_user;
mysql> grant all on db_name.* to ‘db_user’@’localhost’ identified by ‘db_password’;[/code]
More Details

6. Upload the db_backup.sql. This will be imported into your newly created database (from previous step).
user@server2:~$ mysql -u mysql_user -p db_name < db_backup.sql [/code] More Details

7. Update your site’s database settings. For WordPress, update wp-config.php with your info from step 5. For Drupal, update settings.php with your info from step 5.
More Details

8. Add the VirtualHost record to your apache2 configuration file.
8-2. Restart Apache once the new VirtualHost record has been added.
More Details