* [gentoo-dev] Script to post CVS snapshots
@ 2003-10-16 10:18 Donnie Berkholz
0 siblings, 0 replies; only message in thread
From: Donnie Berkholz @ 2003-10-16 10:18 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1.1: Type: text/plain, Size: 470 bytes --]
Hi guys,
I threw together a script to post snapshots to a remote host (CVS or
otherwise), and I thought it might be useful to some of you (especially
developers who get constantly asked to do things like this).
I am using it as a daily cron job to keep a two-week archive of our
stage-building stuff on my website.
The most current version is available here:
http://dev.gentoo.org/~spyderous/scripts/snapshot-archiver
I've also attached a copy.
Donnie
[-- Attachment #1.2: snapshot-archiver --]
[-- Type: text/x-sh, Size: 3077 bytes --]
#! /bin/bash
# Snapshot Archiver, version 0.1
# Copyright 2003 by Donnie Berkholz <spyderous@gentoo.org>
# Licensed under the GNU Public License, Version 2
#
# Purpose: make daily tarball of a project and copy to a remote host,
# deleting tarballs older than a specified age.
DATE="`date +%Y%m%d`"
PROJECT="catalyst"
DIRECTORY="${PROJECT}/"
LOG="/var/log/post-${PROJECT}"
# Ownership for tarball
OWNERSHIP="donnie:users"
# Project source location, one level above project directory
SOURCE="/usr/gentoo/src/"
# Update syntax
UPDATE="cvs update"
# Local location
LOCAL_LOC="/home/donnie/dev/public_html/livecd/"
# Remote location information
LOGIN="spyderous"
REMOTE_HOST="dev.gentoo.org"
REMOTE_LOC="~/public_html/livecd/"
# Archive time in days (two weeks)
TIME="14"
# Tarball name
TARBALL="${PROJECT}-${DATE}.tar.bz2"
# Rsync options
RSYNC_OPTS="-avz -e ssh --delete"
# Rework TIME to seconds so it's understood by the script
TIME_SEC=$(( ${TIME} * 86400 ))
# Start logging
echo "--- Starting post-${PROJECT} for ${DATE} ---" >> ${LOG}
# Move to correct directory in checkout
# and make sure we have the most recent sources
cd ${SOURCE}/${DIRECTORY} && \
${UPDATE} > /dev/null && \
echo "${UPDATE}: success." >> ${LOG} || \
echo "ERROR: ${UPDATE} failed." >> ${LOG}
# Move up a level so we can make a good tarball
# and make the dated tarball
cd .. && \
tar cvfj ${LOCAL_LOC}/${TARBALL} ${DIRECTORY} > /dev/null && \
echo "Making tarball: success." >> ${LOG} || \
echo "ERROR: Making tarball failed." >> ${LOG}
# Should be owned by appropriate user:group
chown ${OWNERSHIP} ${LOCAL_LOC}/${TARBALL} && \
echo "Changing ownership to ${OWNERSHIP}: success." >> ${LOG} || \
echo "ERROR: Changing ownership failed." >> ${LOG}
# Delete tarballs older than ${TIME_SEC}
for i in `ls ${LOCAL_LOC}/${PROJECT}-[0-9]*`
do
unset AGE1
unset AGE2
# Age of all tarballs, one at a time
AGE1="`basename ${i} | sed \"s:${PROJECT}-\(.*\).tar.bz2:\1:g\" | xargs date +%s -d`"
# Age of today's tarball
AGE2="`basename ${LOCAL_LOC}/${TARBALL} | sed \"s:${PROJECT}-\(.*\).tar.bz2:\1:g\" | xargs date +%s -d`"
# If today's tarball minus old tarball > ${TIME_SEC}, then delete
# This line instead of the next one keeps /bin/sh compatibility,
# but it requires sys-devel/bc.
# if [ "`echo \"${AGE2} - ${AGE1} > ${TIME_SEC}\" | bc`" = "1" ]
# The below line loses /bin/sh compatibility.
if [ $((${AGE2} - ${AGE1})) -gt ${TIME_SEC} ]
then
rm ${i} && \
echo "Deleting `basename ${i}`: success" >> ${LOG} || \
echo "ERROR: Deleting `basename ${i}` failed." >> ${LOG}
fi
done
# Rsync tarball(s) to remote host
rsync ${RSYNC_OPTS} ${LOCAL_LOC}/ ${LOGIN}@${REMOTE_HOST}:${REMOTE_LOC} > /dev/null && \
echo "Syncing local and remote hosts: success." >> ${LOG} && \
echo "Copying ${TARBALL} to ${REMOTE_HOST}: success." >> ${LOG} || \
echo "ERROR: ${TARBALL} not posted to ${REMOTE_HOST}." >> ${LOG}
# End logging
echo "--- Ending post-${PROJECT} for ${DATE} ---" >> ${LOG}
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2003-10-16 10:18 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-16 10:18 [gentoo-dev] Script to post CVS snapshots Donnie Berkholz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox