I've written a small utility to facilitate backups of live packages git://die.net.au/crux/tools/pkg-backup.git I also put together a wiki page on how to use it. http://crux.nu/Public/PackageBackups -- Lucas Hazel <lucas@die.net.au>
Heyo Lucas, Lucas Hazel wrote:
I've written a small utility to facilitate backups of live packages
git://die.net.au/crux/tools/pkg-backup.git
Nice!, I like it, and also I wrote a patch (attached) for giving more options. I like the idea of running manually backups too, and also for all my installed ports. I'm using it on my system successfully, with prt-get or manually, and for me it's very useful. Some examples: # pkg-backup Usage: pkg-backup <options> port1 port2... Where options are: -h, --help Show this help information -v, --verbose Verbose output messages -a, --all Backup all ports installed -r, --root path Specify alternative installation root (default: /) # pkg-backup -v -a [acpid] etc/acpi/default.sh etc/acpi/events/default etc/rc.d/acpid usr/bin/acpi_listen usr/man/man8/acpi_listen.8.gz usr/man/man8/acpid.8.gz usr/sbin/acpid [acroread] usr/bin/acroread usr/lib/Acrobat7/Browser/intellinux/nppdf.so usr/lib/Acrobat7/Reader/AcroVersion usr/lib/Acrobat7/Reader/Cert/curl-ca-bundle.crt ... Also to have a manual page would be nice for pkg-backup. I'll be glad to contribute if possible.
I also put together a wiki page on how to use it.
Seems that my patch keeps backwards compatibility with this page :-) Best regards, Jose V Beneyto diff --git a/.md5sum b/.md5sum index c1b42d9..cbc2404 100644 --- a/.md5sum +++ b/.md5sum @@ -1,3 +1,3 @@ -d88d898d3c0b855410bfc24b5125a312 pkg-backup -29133583d54fddad99afa0e654dda821 pkgadd-wrapper -5b4bd41eca97512f4b7a17746100b3d7 pkgrm-wrapper +553b248b1ceb09f5d29eefbf98442eb3 pkg-backup +650517cb793f66b39b6f0037f73d83b8 pkgadd-wrapper +b39ef49dccb38a84132ca2e34dd4d58b pkgrm-wrapper diff --git a/Pkgfile b/Pkgfile index d22f7a0..3274507 100644 --- a/Pkgfile +++ b/Pkgfile @@ -3,15 +3,11 @@ # Maintainer: Lucas Hazel, lucas at die dot net dot au name=pkg-backup -version=0.0a +version=0.0b release=1 source=(pkg-backup pkgadd-wrapper pkgrm-wrapper) build() { - install -d $PKG/usr/bin - for f in ${source[*]}; do - install -o root -g root -m 0755 \ - $f $PKG/usr/bin/$f - done - install -d $PKG/var/cache/pkg-backup + install -d $PKG/{usr/bin,var/cache/$name} + install -o root -g root -m 0755 $SRC/* $PKG/usr/bin } diff --git a/README b/README index dc258d4..115f256 100644 --- a/README +++ b/README @@ -1,6 +1,9 @@ -prt-backup is a utlity for backing up installed packages. + +README + +pkg-backup is a utility for backing up installed packages. To enable automatic backups simply make the following changes to prt-get.conf -addcommand pkgadd-wrapper -removecommand pkgrm-wrapper \ No newline at end of file + addcommand pkgadd-wrapper + removecommand pkgrm-wrapper diff --git a/pkg-backup b/pkg-backup index e34d5d3..1e88465 100755 --- a/pkg-backup +++ b/pkg-backup @@ -1,37 +1,79 @@ #!/bin/sh +msg_error() { + echo "$APPNAME: Error, $@" 2>&1 + exit 1 +} + +msg_usage() { + echo "Usage: $APPNAME <options> port1 port2..." + echo "Where options are:" + echo " -h, --help Show this help information" + echo " -v, --verbose Verbose output messages" + echo " -a, --all Backup all ports installed" + echo " -r, --root path Specify alternative installation root (default: /)" + exit 0 +} + check_installed() { - return `prt-get isinst $1 >& /dev/null` + local port="$1" + [ "$(prt-get isinst $port)" ] || msg_error "port '$port' ins't installed" } backup_port() { - version="`prt-get current $1`" - tar zcf "$PKG_BACKUP_DIR/$1#$version.pkg.tar.gz" \ - -C $ROOT `pkginfo -l $1 | sed '/.*\/$/d'` + local port="$1" + local version="$(prt-get current $port)" + local options="czf" + if [ $VERBOSE -eq 1 ]; then + echo "[$port]" + options="v$options" + fi + tar $options "$PKG_BACKUP_DIR/${port}#${version}.pkg.tar.gz" \ + -C $ROOT $(pkginfo -l $port | sed '/.*\/$/d') + [ $VERBOSE -eq 1 ] && echo } main() { - while [ "$1" ]; do - case $1 in - -r|--root) - if [ ! "$2" ]; then - echo "pkg-backup: option $1 requires an argument" - exit 1 - fi - ROOT="$2" - shift ;; - *) - PORTS="$1 $PORTS" ;; - esac - shift - done - - for port in $PORTS - do - check_installed "$port" && backup_port "$port" - done + while [ "$1" ]; do + case $1 in + -h|--help) + msg_usage + ;; + -v|--verbose) + VERBOSE=1 + ;; + -a|--all) + PORTS="$(pkginfo -i | cut -d' ' -f1)" + ;; + -r|--root) + [ ! "$2" ] && msg_error "option $1 requires an argument" + ROOT="$2" + shift + ;; + *) + PORTS="$1 $PORTS" + ;; + esac + shift + done + for port in ${PORTS[@]}; do + check_installed "$port" + backup_port "$port" + done } +APPNAME="$(basename $0)" +APPVERSION="0.0b" + ROOT="/" -PKG_BACKUP_DIR="/var/cache/pkg-backup" +PKG_BACKUP_DIR="/var/cache/$APPNAME" + +VERBOSE=0 + +[ $# -lt 1 ] && msg_usage + +[ ! -d "$PKG_BACKUP_DIR" ] && mkdir -p $PKG_BACKUP_DIR + main $@ + +# End of file diff --git a/pkgadd-wrapper b/pkgadd-wrapper index 85bfc96..76e75b3 100755 --- a/pkgadd-wrapper +++ b/pkgadd-wrapper @@ -1,30 +1,31 @@ #!/bin/sh -ARGS=$@ + +[ $# -lt 1 ] && exit 1 + +PKGADD_ARGS=$@ +UPGRADE=0 + while [ "$1" ]; do - case "$1" in - -r|--root) - if [ ! "$2" ]; then - echo "pkgadd-wrapper: option $1 requires an argument" - exit 1 - fi - ROOT="$2" - shift ;; - -u|--upgrade) - UPGRADE="true" ;; - -*) - ;; - *) - PACKAGE="$1" - esac - shift + case "$1" in + -r|--root) + PKG_BACKUP_ARGS="$PKG_BACKUP_ARGS $1 $2" + shift + ;; + -u|--upgrade) + UPGRADE=1 + ;; + -*) + ;; + *) + PACKAGE="$(basename $1 | sed 's/#.*//')" + PKG_BACKUP_ARGS="$PKG_BACKUP_ARGS $PACKAGE" + ;; + esac + shift done -if [ "$UPGRADE" = "true" ]; then - PACKAGE="`basename $PACKAGE | sed 's/#.*//'`" - if [ "$ROOT" ]; then - pkg-backup -r "$ROOT" "$PACKAGE" - else - pkg-backup "$PACKAGE" - fi -fi -pkgadd $ARGS \ No newline at end of file +[ $UPGRADE -eq 1 ] && pkg-backup $PKG_BACKUP_ARGS + +pkgadd $PKGADD_ARGS + +# End of file diff --git a/pkgrm-wrapper b/pkgrm-wrapper index 4e17c80..a2c9582 100755 --- a/pkgrm-wrapper +++ b/pkgrm-wrapper @@ -1,23 +1,27 @@ #!/bin/sh -ARGS=$@ + +[ $# -lt 1 ] && exit 1 + +PKGRM_ARGS=$@ + while [ "$1" ]; do - case $1 in - -r|--root) - if [ ! "$2" ]; then - echo "pkgrm-wrapper: option $1 requires an argument" - exit 1 - fi - ROOT="$2" - shift ;; - *) - PACKAGE="$1" ;; - esac - shift + case "$1" in + -r|--root) + PKG_BACKUP_ARGS="$PKG_BACKUP_ARGS $1 $2" + shift + ;; + -*) + ;; + *) + PACKAGE="$(basename $1 | sed 's/#.*//')" + PKG_BACKUP_ARGS="$PKG_BACKUP_ARGS $PACKAGE" + ;; + esac + shift done -if [ "$ROOT" ]; then - pkg-backup -r "$ROOT" "$PACKAGE" -else - pkg-backup "$PACKAGE" -fi -pkgrm $ARGS \ No newline at end of file +pkg-backup $PKG_BACKUP_ARGS + +pkgrm $PKGRM_ARGS + +# End of file
Hi, On Mon, Jun 09, 2008 at 17:03:19 +1000, Lucas Hazel wrote:
I've written a small utility to facilitate backups of live packages
git://die.net.au/crux/tools/pkg-backup.git
I also put together a wiki page on how to use it.
Nifty. I like how this can be hooked in easily. Any plans to add a 'depth' parameter to set the number of backed up packages per port? Also, I think this would make a nice addition to prt-utils. Would that be okay with you? Cheers, Johannes -- Johannes Winkelmann mailto:jw@smts.ch Zurich, Switzerland http://jw.smts.ch
On Sun, 22 Jun 2008 12:30:07 +0200 Johannes Winkelmann <jw@smts.ch> wrote:
Hi,
On Mon, Jun 09, 2008 at 17:03:19 +1000, Lucas Hazel wrote:
I've written a small utility to facilitate backups of live packages
git://die.net.au/crux/tools/pkg-backup.git
I also put together a wiki page on how to use it.
Nifty. I like how this can be hooked in easily. Any plans to add a 'depth' parameter to set the number of backed up packages per port?
That's a good idea, should be pretty easy to implement. I'm also planning to add a bit of verbosity to it.
Also, I think this would make a nice addition to prt-utils. Would that be okay with you?
Yeah, no worries. In that case I might give the wrappers more specific names, like pkgrm-backup and pkgadd-backup or something. -- Lucas Hazel <lucas@die.net.au>
participants (3)
-
Johannes Winkelmann
-
Jose V Beneyto
-
Lucas Hazel