lamp-backup :: Backing up LAMP Server Content

February 28th, 2012 No comments

It’s been a while since I posted anything useful, but hopefully this will make up for it.

A friend came to me asking for help configuring the backup of his remote LAMP server and I duly obliged, but ended up getting a little carried away. Some hours later I emerged with this bash script to do the job properly.

Called from cron, each time the script runs:

  • It creates/updates a local rsync-copy of a remote directory.
  • It runs a mysqldump to a file, named by date-stamp.
  • Any archives or log files older than the user-specified expiry time (days) are deleted.
  • All three operations are carefully logged to appropriate “.log” and “.err” files.
  • The mysqldump, the rsync-copy and all the logs are run through tar.
  • The tarball is run through a user-specified compression program (default: xz).
  • The final archive is named by date-stamp.
  • A summary file is created including highlighted errors and execution times for each step.
  • The summary.log is (optionally) e-mailed to the backup administrator.
  • The script cleans up after itself, deleting any superfluous log and mysqldump files.

In the end you have a configurable period of snapshotted-history for your LAMP server, all in small archive files, named by their date and with logs for every step of every backup and permanently-deleted file.

I recommend the script is called by cron like this (assuming midnight backup):

0 * * * * /path/to/lamp-backup.sh 1>/path/to/lamp-backup/lamp-backup.log 2>/path/to/lamp-backup.err

Which will also give you activity and error logs for the script itself.

If you wish to run the script manually from the command line to test it, you can set the output to verbose like this:

$ VERBOSE=true ./lamp-backup.sh



Ensure that lamp-backup.conf lives in the same directory as lamp-backup.sh and is readable and carefully configured.

DO NOT RUN THIS SCRIPT AS ROOT UNLESS YOU REALLY NEED TO AND HAVE TESTED YOUR CONFIGURATION AS A NORMAL USER.



You can get a copy of v1.0 (stable) of this script and associated config file from my subversion repository:

https://svn.tpa.me.uk/lamp-backup/tags/1.0

I will be working on it more soon, abstracting further, adding command line parameters and adding additional features that seem useful.

You can track the current version via the repository trunk.

Categories: Apache, Linux Tags: , , , , ,

Rosetta Code

June 1st, 2011 No comments

Stumbled across the Rosetta Code site this morning. I can’t remember when I last discovered a site so unbelievably useful; especially for people like me who occasionally dip into languages and then don’t use them again for a long time.

http://rosettacode.org/

Rosetta Code is a programming chrestomathy site. The idea is to present solutions to the same task in as many different languages as possible, to demonstrate how languages are similar and different, and to aid a person with a grounding in one approach to a problem in learning another. Rosetta Code currently has 504 tasks, and is aware of 384 languages, though we do not (and cannot) have solutions to every task in every language.

A very good example from the site:

http://rosettacode.org/wiki/Reverse_a_string

Slackware 13.37 Released

April 28th, 2011 No comments

Slackware-13.37 (and Slackware64-13.37) has been released today and I must say I’m extremely happy with it. I previously posted that I thought 13.1 was rushed, and it was, but this release is the polar opposite. Slackware-13.37 has been in beta for nearly two months and has been getting bugfixes, small updates and tweaks that whole time. I’m confident that this is quite simply the best version of Slackware ever to get through the stable door.

I want to personally extend my thanks to the whole Slackware team for their constant efforts to make the core of my infrastructure (and yours too) as good as it can be.

Want a copy now? Right now? Ok. Here’s the official torrents :)

Torrents for Slackware 13.37, 32-bit x86

Torrent for Slackware 13.37, 64-bit x86_64

Slackware 13.37 – Xorg + Hal

March 29th, 2011 3 comments

The divorce was a long time coming. The papers are finally signed. Xorg has dumped hal and eloped with udev.

Keyboard layout modifications are back to (almost) normal – but instead of using /etc/X11/xorg.conf, we’re now using /etc/X11/xorg.conf.d/90-keyboard-layout.conf.

To change your keyboard layout from US to GB (for example):

# cp /{usr/share,etc}/X11/xorg.conf.d/90-keyboard-layout.conf
# vi /etc/X11/xorg.conf.d/90-keyboard-layout.conf

Modify the file to replace:

Option “XkbLayout” “us”

With:

Option “XkbLayout” “gb”

.. just as you would have done a few years ago with xorg.conf.

Upgrading Slackware64-current with multilib

March 12th, 2011 No comments

In order to upgrade your multilib Slackware64-current box to a more recent -current (or perhaps 13.37):

  1. Make sure you have a copy of the version you want to upgrade to available.
  2. Make sure your slackpkg config points to it
mkdir -p /mirror/slackware
cd !$
lftp -c "open http://connie.slackware.com/~alien/; mirror multilib"
slackpkg update
slackpkg install-new
slackpkg upgrade-all
upgradepkg --reinstall --install-new  /mirror/slackware/multilib/current/{*.t?z,slackware64-compat32/*/*.t?z}
slackpkg clean-system

Bear in mind that you need to know what modifications you’ve made to your system in the “clean-system” stage. slackpkg will offer to remove any package that’s not part of the version you’re upgrading to. If you need to keep any extra packages that you’ve installed you need to make sure you don’t uninstall them at this stage. For this reason I heavily recommend that you blacklist SlackBuilds.Org packages in the slackpkg blacklist file.

Blog Downtime

September 6th, 2010 No comments

Sorry for the downtime over the last couple of days, people. My server decided to barf up its kernel while I was away camping and driving an M3 and a DB9 for my birthday. Typically, the server was only 5 days from its first uptime anniversary.

Normal service has now been resumed.

Categories: Miscellaneous Tags:

Sad Day :: Company Bought

July 26th, 2010 No comments

My company has been bought. While this means a lot of good and bad all over the place, it means one thing that’s very sad; I am about to commence work on tearing down the network I have so lovingly crafted over the last four years. Within a year I don’t expect there to be more than one or two Slackware boxes still running, if any. Black armbands please.

Categories: Slackware Tags: , , ,

Slackware 13.1 & libxfs.h

July 12th, 2010 No comments

I was trying to build partclone to read an image created with clonezilla, and discovered it won’t build with XFS support on Slackware because Slackware lacks libxfs.h. I think this is somewhat intentional in that the XFS Makefile only installs the header if you explicitly target “install-qa”. It seems libxfs.h is only supposed to be used by XFS devs and 3rd party software should not require it, and I’m happy with that.

Just in case there is a reason you should need libxfs.h on Slackware:

cp -a /mirror/slackware/slackware-13.1/source/a/xfsprogs ~/.
cd ~/xfsprogs
sed -i -e '93i\make install-qa DIST_ROOT=\$PKG' -e 's/\(BUILD:-1\)/\1qa/' xfsprogs.SlackBuild
./xfsprogs.SlackBuild
upgradepkg /tmp/xfsprogs*1qa.t?z

You now have libxfs.h installed at /usr/include/xfs/libxfs.h

Categories: Slackware Tags: ,

SlackBuilds :: Watch Out For umask

July 8th, 2010 No comments

If you are building your own packages from SlackBuild scripts, then you need to make sure your umask is 022 before you start!

Because of the nature of the shared environment in which I work, I changed my default umask to 002 in /etc/profile. I’ve just discovered a big problem as a result. When directories such as $PKG/etc aknd $PKG/usr are created as part of the SlackBuild, they are created with file permission 775 as per the umask. Then when it comes to installing those directories from the package, the installer overwrites the permissions on the directories in your system with the permissions set in the package.

So, if $PKG/etc was created with 775, your /etc directory will be modified from 755 to 775 and this can do harm. This especially the case with directories such as /etc/mail which are checked by daemons for security before they run. If the permissions are too loose, the daemons don’t run.

Before you run a SlackBuild script, check that your umask is 022!!

Slackware trying to mount NFS shares before the network is ready

June 14th, 2010 4 comments

I have a right pain of a problem in this network in that individual machines are slow to get network access at boot. I haven’t had the opportunity to properly find out why, but my instinct says the blame lies with the Allied Telesyn switches.

The big problem this causes is that any machines with a remote filesystem, such as an NFS share, in their fstab fail to mount the shares at boot; which means I have to manually ssh in and issue a mount command as root.

The solution is to ask rc.inet2 if it would kindly consider waiting just a little longer for the network to come up and not mount remote filesystems if it doesn’t.

The following patch attempts to ping an always-on host, preferably the host that serves the filesystem(s) you are going to mount.

  • If a response is received, the boot process continues as normal.
  • If there’s no response to the first ping:
    • A further 5 pings are attempted.
    • A countdown is displayed.
    • After 6 failed attempts boot continues, but with no attempt to mount remote filesystems.

rc.inet2.diff (download rc.inet2.diff.gz):

--- ./rc.inet2.orig     2007-09-17 23:07:32.000000000 +0100
+++ ./rc.inet2  2010-06-14 14:05:24.237107265 +0100
@@ -15,9 +15,16 @@
 
 # At this point, we are ready to talk to The World...
 
+lan_test_host="<known up host, or remote filesystem server>";
+avail=6;
+while ! ping -c1 $lan_test_host &>/dev/null && (( avail-- > 1 ));
+do
+       echo "Waiting for network before mounting remote filesystems... $avail";
+       sleep 1;
+done
 
 # Mount remote (NFS) filesystems:
-if cat /etc/fstab | grep -v '^#' | grep -w nfs 1> /dev/null 2> /dev/null ; then
+if cat /etc/fstab | grep -v '^#' | grep -w nfs 1> /dev/null 2> /dev/null && ((avail)); then
   # Start rpc.portmap, /sbin/rpc.lockd, and /sbin/rpc.statd if we find NFS
   # volumes defined in /etc/fstab since these will need to be running in order
   # to mount them.  If they are not running, attempting to mount an NFS
@@ -46,7 +53,7 @@
 
 # Mount remote CIFS filesystems.  Note that where possible, using CIFS is
 # preferred over SMBFS.  SMBFS is no longer actively maintained.
-if cat /etc/fstab | grep -v '^#' | grep -w cifs 1> /dev/null 2> /dev/null ; then
+if cat /etc/fstab | grep -v '^#' | grep -w cifs 1> /dev/null 2> /dev/null && ((avail)); then
   echo "Mounting remote CIFS file systems:  /sbin/mount -a -t cifs"
   /sbin/mount -a -t cifs
   # Show the mounted volumes:
@@ -54,7 +61,7 @@
 fi
 
 # Mount remote SMB filesystems:
-if cat /etc/fstab | grep -v '^#' | grep -w smbfs 1> /dev/null 2> /dev/null ; then
+if cat /etc/fstab | grep -v '^#' | grep -w smbfs 1> /dev/null 2> /dev/null && ((avail)); then
   echo "Mounting remote SMBFS file systems:  /sbin/mount -a -t smbfs"
   /sbin/mount -a -t smbfs
   # Show the mounted volumes:

In order to apply the above patch, do the following as root:

# cd /etc/rc.d
# wget http://blog.tpa.me.uk/wp-content/uploads/2010/06/rc.inet2.diff.gz
# zcat rc.inet2.diff.gz | patch -p1

Do not forget to manually edit your newly patched file to replace “<known up host, or remote filesystem server>” with a valid hostname or IP address.