How we back up all sites

According to our rules the customers are fully responsible for backing up their websites and databases. However, that doesn’t mean that we don’t run any backups at all. We run backups for the entire server and in case of any emergency we’ll try to restore them as quickly as possible.

For the ones who are familiar with computer technology we’d like to show how an average backup should be handled. The information below applies if you have a dedicated server and several websites on it with MySQL being the back-end.

Backup stages

We divide backup process into several stages:

  1. Backup of website files
  2. Backup of databases
  3. Regular backup of everything

Backup of website files

To backup files we should know where they are located and then we run this backup command for every website we have:

tar -czf website_name.tar.gz /home/website/

Backup of databases

Let’s assume that we know login details to the database of the website we backed up above:

mysqldump -u username -ppassword database_name > database.sql

To save disk space it would be good to zip that MySQL dump with the gzip command.

mysqldump -u username -ppassword database_name | gzip > database.sql.gz

Regular backup of everything

To automate the backup process it’s better run it periodically with a special script. The cron will help us with it! The cron is a clock utility for Linux that executes commands at specified dates and times, but first of all we need to create our special script (hmm.. let’s call it “backup.sh”) and save it. Then, add it to the cron job schedule:

The backup script:

#!/bin/bash
tar -czf website_name.tar.gz /home/website/;
mysqldump -u username -ppassword database_name | gzip > database.sql.gz;

Ok, guys it’s time to add to the cron job. Run cronjob command with the -e (edit) option:

crontab -e

As a result we should see something like that:

0 1 * * 1 /usr/bin/errclear -m
0 1 * * 2 /usr/bin/errclear -w

It doesn’t really matter what the lines, starting from “/usr…” do. These lines are just the absolute paths to the scripts and programs that will be executed. But it’s matter what the numbers and stars before them means. These 5 columns telling the cron what date and time the script/program should run:

  1. Minutes. 00-59
  2. Hours 00-23
  3. Day in a month 01-31
  4. Month in a year 01-12
  5. Day of the week 0-6, where the Sunday is 6

Let’s assume that our script is located on /backup/backup.sh and we want to run it every Friday at 22:37 forever. In that case we should add the line like this:

37 22 * * * /backup/backup.sh

So in the cron job schedule edit mode we would see:

0 1 * * 1 /usr/bin/errclear -m
0 1 * * 2 /usr/bin/errclear -w
37 22 * * 4 /backup/backup.sh

Save the cron job schedule and exit it. Now our backup will run every Friday at 22:37

Increasing the chances of survival of site backup

Now we have backups of the database and website files, but we have a little issue with the reliability. They are all located on the same server with our websites. This is a not good practice to leave them there, so we need to regularly download backup files to another server or local PC/Mac.

How to create symbolic link in Linux

It's a piece of cake. Just run the following command in the directory where you want to create that symbolic link:

ln -s /desired_directory

Then if you need that directory to be available in your website, add this directive to your htaccess file:

Options FollowSymLinks

Have any issues or questions about your Linux machine? Ask our specialists, using the form on the right side.

Update MySQL where id in range and use md5

In MySQL sometimes we need to update a set of rows within the specific range of ids. If the range is short then we can use the ID IN (ids) argument. If it's long and we know that range, let's use the BETWEEN value AND value argument.

UPDATE `table` SET `password` = (SELECT MD5(uniqueName)) WHERE `id` BETWEEN 863 AND 987

Getting disk size in Linux

It's very simple to get the disk size and its utilization in Linux. Just run this command:

df

In return you should see something like that:

user [/home/]# df
Filesystem	1K-blocks	Used	Available	Use%	Mounted on
/dev/sda7	2063504	15775	381136		81%	 /
/dev/sda1	1035660	51652	931400		6% /boot
/dev/sda8	4529120	103776	326129		25%	 /home
/dev/sda6	2063504	58300	1900384	3% /tmp

Installing OpenX ad server

Although generally a simple task installing OpenX ad server can be somewhat tricky. The basic requirements for it are PHP5 and MySQL or PostgreSQL. Make sure you have these on your server by running [?phpinfo();?] from an info.php file. In some cases you might need to set your control panel to use PHP5. See our article for that.

Follow these simple instructions to install OpenX server

  1. Download the latest OpenX archive from openx.org and upload it to a folder in your hosting account. For example: /ads. We recommend creating a sub-domain for it. Something like: ads.your_domain.com
  2. Expand the OpenX archive and make sure all files are in the directory you created. If you're using cPanel use Extract utility from the File Manager and then move the extracted files to the installation folder
  3. Create a database and take a note of the database name, user name and user password. You will need them during the installation
  4. Set the 777 permissions on the following folders: /var and /images. You should do this from an FTP client and make sure to select recursive permission change. Otherwise, the installation script will give you an error.

  5. Open up the folder where you extracted OpenX to. This will launch the installation process.
  6. Follow the installation steps to finish everything up.

After this you can log in to OpenX and start learning it

We can install OpenX for you professionally. Feel free to contact us for a quote.