Thursday, 14 of September of 2006

To maintain a periodic backup of your blog/data base

Today in this blog on Palm we will concentrate more in the part `blog' that in the part `Palm'. Creo that what comes next can enough be interesting for people, those that do not have blog but another type on watch or Web site that uses data bases, are even already vestibules, forums, etc.

Days ago as you know I updated the version of WordPress (software CMS with that blog works this) to version 2.0.4, that is being stable and for anything problematic. Nevertheless, yes that has arisen a problem. We go by parts.

WordPress brings by defect plugin to make periodic backups of the data base, from which all the can be recovered posts, commentaries, and other information after a disaster, or to clonar blog complete in a new servant. Its name is wp-db-backup and does a work brilliant, with the possibility of keeping the backup in our servant, or of sending it to us by email, and most important, combined with plugin wp-cron, we could program a daily backup, and that arrived to us by email.

Plugin is excellent, and I have used in fact it without problems during months. But unfortunately its development paused a year ago, and in version 2.0.4 of WordPress it has stopped working the capacity to program backups. The same author informs to us in this commentary that has stopped working in him, and it has not proven it with this last version. So unless another developer takes the relief and corrects plugin, it will not return to work in this one and the following versions of WordPress.

Of course it did not want to have to execute every day plugin by hand, because it knew that sooner or later (rather before) it was going to forget to me. So looking for by the network, and proving several alternatives, I have ended up writing simple script in Bash that realises a daily backup of the data base and the guard in the servant, maintaining the N last versions and erasing the previous ones. Also the option could be added to him to send the file by email, but in my servant I do not have possibility of doing it. It would not be more than to add a line of code:

/bin/mail - s “subject” “direction” < archivo="">

So that this script works, the servant in whom you have lodged blog must use Linux, to use MySQL like basic software of data, and daros the possibility of creating periodic works in Cron. Script is the following one:

mysqldump --add-drop-table --to user “nombre_usuario” --password= " password” “base_de_datos” | gzip -9 > /home/ " usuario_cpanel”/“directorio_backup”/“base_de_datos”. `dates --iso-8601 `.gz
ls - t /home/” usuario_cpanel”/” directorio_backup”/” base_de_datos”. * | tail ” número_copias_más_1 ″ | xargs rm - f

Sight thus seems horrible (in fact they are only two lines, in this close format of column are cut), but a little later I will give a connection you to unload it directly and to form it. Everything what goes in inverted commas is data that you will have to replace by the corresponding values (without the quotation marks). We see its explanation one by one:

  • “nombre_usuario”: the name of the user who has access to the data base. He is the one that tuvísteis that to write in the file wp-config.php during the installation.
  • “password”: the password to accede to the data base. She is the one that tuvísteis that to write in the file wp-config.php during the installation.
  • “base_de_datos”: the name of the data base. Also tuvísteis that to write in the file wp-config.php during the installation.
  • “usuario_cpanel”: it is your name of user in the servant of hosting. Surely he is the one that you use to accede to the Control Panel.
  • “directorio_backup”: the directory in whom the backups will keep. You must create it for example entering by FTP your account. I recommend to make it in the root directory, the one that nothing else appears to accede. You will have to give writing permissions him so that script can use it (this becomes by means of the attributes of the directory that you finish creating, any program of decent FTP will let change them to you). For example you try with 777 (permission of reading and writing for all). If that directory is outside the directory where the content keeps from your installation of WordPress (typically public_html), nobody will be able to accede via Web to him.
  • “número_copias_más_1 ″: simply that. If you want to keep three last copies, you put 4.

In order to understand better script, we see as it would be with concrete data:

mysqldump --add-drop-table --to user alpaca --password=paquito pacodb | gzip -9 > /home/paco_server/mysql_backups/pacodb. `dates --iso-8601 `.gz
ls - t /home/paco_server/mysql_backups/pacodb. * | tail 3 | xargs rm - f

You can directly unload the code in a text file. You call for example db_backup.sh, cambiais the previous variables of example by yours, and you raise by FTP the root directory to it of your servant. In the attributes of the file, you must give to permission of execution for user and group, for example you put 754. He is already ready to use.

Example of a panel cPanel, where to form the Cron
Example of a panel cPanel, where to form the Cron

Now we must create the work in Cron it executes so that it periodically. That becomes from the Control Panel of your account in the servant. For example, the servant who lodges this blog that you read, uses software cPanel like Control Panel, and surely it will be the case of many others, given his popularity. In my case the option is called Cron jobs. We enter and we chose to create one new one. Like commando to execute, we introduce the route to ours script, for example:

/home/pepe/backup.sh

And like regularity, for example every six hours, of every day, months and years. In format Cron de Unix it would be therefore the line to add:

0 */6 * * * /home/pepe/backup.sh

We keep the changes, and script is already programmed the execution of ours every six hours. That is to say, four times to the day a copy will be made of our data base in this directory. The daily archives will be accumulated during the day that we say, and when they are older than that, they will erase. With this system, if someday we put the leg when changing something in blog, we can return easily to a previous state, following these instructions.

I hope that the process has been moderately clear, although if never you have cacharreado with Cron works or data bases, it will be better than somebody more customary to work with servants makes use to you. In return, you will have a backup of yours blog that, creedme, arrived the moment is worth its weight in gold.


Related articles


14 commentaries on “Maintaining a periodic backup of your blog/data base”


Pages: [1] 2

Pages: [1] 2

It leaves a commentary


Valid labels: <a href= "" title= "" > <abbr title= "" > <acronym title= "" > <b> <blockquote cite= "" > <cite> <code> <de datetime= "" > <em> <i> <q cite= "" > <strike> <strong>

Akismet has already protected this blog of thousands of fraudulent commentaries. But by error avísame by means of the email of contact of the right filters your commentary please.