Archive for February, 2007

My daily backup

Thursday, February 22nd, 2007

I recently recovered my files from my daily backup, which had actually worked!

(Pop quiz: this is how I deleted half my home dir – what is wrong with this Makefile?

TMP_DIR=/tmp/gssmp

blah: blah1
    blah

...

blah7:
    ...
    rm -rf $TMPDIR/

...

)

Anyway, I am extremely grateful that the backup did work, but a slight problem was that I have been backing up absolutely everything, and never deleting anything that was backed up until I ran out of disk space.

So when I restored from backup, every file I had ever deleted (since I started backing up) re-appeared. This included files and dirs (and email) that had just been moved somewhere else – I now had 2 copies of them.

I’ve spent the night deleting stuff that I didn’t actually want restored, and this has encouraged me to create an improved backup script that puts deleted stuff into a separate folder, named after the day it was deleted. I can delete those folders at my leisure when they get too big, but when a disaster happens like it did on Wednesday, I can restore back to a sane state by just ignoring any irrelevant deleted folders.

It’s quite simple, but I hadn’t thought of it before, so it might be helpful to others. Enjoy:

#!/bin/bash

# Copy this to /etc/cron.daily and make it owned by root, and executable

# Back up everything important from my main drive (hda) to the backup
# drive (hdb).

# Keep stuff that has been deleted from the real drive in a separate
# backup dir, named after the day it was deleted.

BKP_DRIVE=/media/hdb1

FLAGS="-a --delete-during --max-delete 100 --backup"

DT=`date +%F`
DELETED_DIR=deleted-$DT

function run_rsync
{
    THIS_DIR=$1
    EXCLUDES=$2

    echo rsync $FLAGS --backup-dir=$BKP_DRIVE/$DELETED_DIR$THIS_DIR \
        $EXCLUDES $THIS_DIR/ $BKP_DRIVE$THIS_DIR/
    rsync $FLAGS --backup-dir=$BKP_DRIVE/$DELETED_DIR$THIS_DIR \
        $EXCLUDES $THIS_DIR/ $BKP_DRIVE$THIS_DIR/
}

run_rsync /home/andy \
    "--exclude /iRiver --exclude /downloads --exclude /.Trash --exclude /misc/qemu"

run_rsync /etc

run_rsync /var

run_rsync /boot

Creating .deb and RPM packages

Thursday, February 22nd, 2007

Since I’ve managed to get it to work for GSSMP, I thought I might share how I am generating .deb and RPM packages using a Makefile. These make it much easier for Ubuntu and Fedora Linux users (respectively) to install the program. It should also be helpful for people using Debian, who can try the .deb, and other RPM-based distros, who can try the RPM.

This project is all autotooled-up, so this may not be very helpful if you don’t use autotools.

(Side tip: I don’t understand autotools at all, but since I created the project with glade, it did all the hard work for me.)

I created these files for the Ubuntu .deb package:

changelog:

gssmp (0.8-0ubuntu1) edgy; urgency=low

  * First release packaged for ubuntu

 -- Andy Balaam <myemailaddress>  Thu, 15 Feb 2007 12:33:11 +0000

copyright:

This package was debianized by Andy Balaam <myemailaddress> on
Thu, 15 Feb 2007 12:33:11 +0000.

It was downloaded from

http://sourceforge.net/project/showfiles.php?group_id=187144&package_id=219138

Copyright Holder: Andy Balaam <myemailaddress>

License:
   This package is free software; you can redistribute it and/or modify
   blah blah blah GPL boilerplate

control:

Source: gssmp
Section: sound
Priority: optional
Maintainer: Andy Balaam <myemailaddress>
Build-Depends: debhelper (>= 4.0.0), autotools-dev, libgstreamer0.10-dev, libgnomeui-dev
Standards-Version: 3.6.2

Package: gssmp
Architecture: any
Depends: libgstreamer0.10-0, libgnomeui-0
Description: Gnome Simple Stateful Music Player
 GSSMP is a music player designed to work with Gnome.  It does not store a
 database of all your music, but is designed to work with music files organised
 into directories.  It is small, unobtrusive, and tries to do what you would
 expect, instead of asking you questions.
 .
 It remembers which file was playing on exit, and continues that file from the
 same place when you start again.  It remembers tracks you have been listening
 to recently and displays them in the "Recent" menu.

I put those three files in my source tree under install/deb/.

For the RPM, I just needed one file, gssmp.spec:

###
### RPM spec file for Gnome Simple Stateful Music Player
###
### Adapted from jEdit's spec file http://www.jedit.org
###
Summary: A music player that doesn't interfere.
Name: gssmp
Provides: gssmp
Version: 0.8
Release: 1
License: GPL
Group: Applications/Multimedia/
Source0: %{name}-%{version}.tar.bz2
URL: http://gssmp.sourceforge.net/
Vendor: Andy Balaam <myemailaddress>
Packager: Andy Balaam <myemailaddress>
BuildArch: i386
BuildRoot: %{_builddir}/%{name}-root
Requires: libgnomeui, gstreamer
BuildRequires: libgnomeui-devel, gstreamer-devel

%description
GSSMP is a music player designed to work with Gnome.  It does not store a
database of all your music, but is designed to work with music files organised
into directories.  It is small, unobtrusive, and tries to do what you would
expect, instead of asking you questions.

It remembers which file was playing on exit, and continues that file from the
same place when you start again.  It remembers tracks you have been listening
to recently and displays them in the "Recent" menu.

%prep
%setup -n %{name}-%{version}

%build
./configure --prefix=/usr
make

%install
make DESTDIR=%{buildroot} install

%clean
rm -rf %{buildroot}

%files
/usr/bin/gssmp
/usr/share/doc/gssmp/AUTHORS
/usr/share/doc/gssmp/COPYING
/usr/share/doc/gssmp/INSTALL
/usr/share/doc/gssmp/NEWS
/usr/share/doc/gssmp/README
/usr/share/doc/gssmp/TODO

which I put in install/rpm

Then I modified my Makefile.am to build the deb and RPM when I told it to:

APP_NAME=gssmp

# Create a deb package
pkg-deb: pkg-src
        - rm -r $(TMP_DIR)
        mkdir -p $(TMP_DIR)
        cp pkg/$(APP_NAME)-$(VERSION).tar.bz2 $(TMP_DIR)/
        tar --directory $(TMP_DIR)/ \
                -xjf $(TMP_DIR)/$(APP_NAME)-$(VERSION).tar.bz2
        cd $(TMP_DIR)/$(APP_NAME)-$(VERSION)/; \
                echo | dh_make --single --copyright gpl -e myemailaddress -f \
                        ../$(APP_NAME)-$(VERSION).tar.bz2
        cp install/deb/changelog install/deb/control \
                install/deb/copyright $(TMP_DIR)/$(APP_NAME)-$(VERSION)/debian/
        cd $(TMP_DIR)/$(APP_NAME)-$(VERSION)/; \
                rm debian/README.Debian debian/*.ex debian/*.EX; \
                ./configure; \
                dpkg-buildpackage -rfakeroot; \
                mv ../*.deb $(PWD)/pkg/
        rm -r $(TMP_DIR);

# Create an RPM package
pkg-rpm: pkg-src
        mkdir -p $(HOME)/.rpm/RPMS/i386
        mkdir -p $(HOME)/.rpm/SRPMS
        mkdir -p $(HOME)/.rpm/BUILD
        mkdir -p $(HOME)/.rpm/SOURCES
        mkdir -p $(HOME)/.rpm/tmp
        - rm -r $(HOME)/.rpm/BUILD/$(APP_NAME)-root
        - rm -r $(HOME)/.rpm/RPMS/$(APP_NAME)-*
        - rm -r $(HOME)/.rpm/SRPMS/$(APP_NAME)-*
        - rm -r $(HOME)/.rpm/SOURCES/$(APP_NAME)-*
        cp pkg/$(APP_NAME)-$(VERSION).tar.bz2 $(HOME)/.rpm/SOURCES/
        rpmbuild --quiet --nodeps --define="_topdir $(HOME)/.rpm" \
            -ba install/rpm/gssmp.spec
        mv $(HOME)/.rpm/RPMS/i386/$(APP_NAME)-$(VERSION)-*.i386.rpm pkg/

Now I just needed to run ./autogen.sh to regenerate my Makefile, and then make pkg-deb or make pkg-rpm and the deb or RPM appears magically in the pkg/ directory.

Autotools, for all its faults, does make this stuff relatively easy. All the code for installing in different places (installing at all) and general flexibility is done for you. Of course, it’s at the expense of ever understanding what’s going on, but you can’t have everything.

Now I just need to make a man page … and fix all the bugs … oh, and make an icon … and make it accept a filename on the command line … and sort out MIME types … etc … so it should be finished really soon.

About Andy Balaam

Friday, February 9th, 2007

You can find out more about me on my home page, www.artificialworlds.net.

Moved to WordPress

Friday, February 9th, 2007

I’ve moved my blog to WordPress, which will allows you to comment on my posts.

I guess it’s a sad day for DIYBlog, but hey, it was just a workaround until I got some web space that supported PHP.

Happy interaction!