Peter Glaeser

online and mobile affiliate marketing news

Backup Scripts for Your Server

In a previous comment I was asked to post a backup procedure that I use on my root servers. The following is a backup stategy that I use on my SuSE servers.

Backup directories

You create the following directories:

  • /root/backup/scripts
  • /root/backup/files

Hourly backup script

Create /root/backup/scripts/1h.sh with the following contents and make it executable:
tar -czf /root/backup/files/partial_`date +%Y-%m-%d_%H-%M`.tar.gz `find /etc /home /srv /var -type f -mmin -60` 2> /dev/null
find /root/backup/files -name 'partial*' -mtime +7 -exec unlink '{}' \;

This creates backups of files that were changed in the past 60 minutes. Also it deletes those hourly backups that are older than 7 days.

Daily backup script

Create /root/backup/scripts/1d.sh with the following contents and make it executable:
rm /root/backup/files/complete*
tar -czf /root/backup/files/complete.tar.gz /etc/ /home/ /srv/ /var/ 2> /dev/null
lftp ftp://#username#:#password#@#host# -e "put /root/backup/files/complete.tar.gz; quit"

This creates a full daily backup of the important files of your server. That complete backup is then copied to an external FTP server. That way you can access your backup even if the whole machine becomes inaccessible. You may need to install the lftp program if it’s not on your machine by default.

You don’t need to create separate MySQL dumps. The MySQL data are stored in the /var structure, in my case under /var/lib/mysql/#database#.

  • 1 Comment
  • Filed under: Technology
  • Crashed WordPress MySQL Tables

    Today I received a couple of my emails telling me that all posts of this blog were deleted. At first I thought people were kidding but then I got really scared. At first I thought somebody had hacked into my WordPress. But I always update all my blogs on the same day a new WordPress version comes out.

    It turned out that the MySQL table containing the posts crashed. The MySQL log told me that by post table “is marked as crashed and should be repaired”. Great! But a little bit of research solved the problem. You need to go to the corresponding MySQL database directory, for example /var/lib/mysql/wordpress, and execute the following commands as root:

    /etc/init.d/mysql stop
    myisamchk -r wp_posts.MYI
    /etc/init.d/mysql start

    Problem solved within a few seconds. If that hadn’t worked I would have used my backups that are created hourly. Let me know if I should write something about backup strategies for standard root servers too.

  • 1 Comment
  • Filed under: Technology
  • watching two girls undress while working on a laptop in the park.
    Follow me on Twitter