From: Carl N Baldwin Date: Sun, 27 Nov 2005 00:30:51 +0000 (-0700) Subject: Merge up to alan's release X-Git-Tag: release-0.4~14 X-Git-Url: http://git.pippins.net/embedvideo/.git/static/git-logo.png?a=commitdiff_plain;h=30e31c8d36fd4b0e12ab99fdcba347089000b0a7;hp=31e73cf58bbda828b42c96e0c02eda6435d4f929;p=backups%2F.git Merge up to alan's release --- diff --git a/.gitignore b/.gitignore index 3201815..c72ba0b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ configure depcomp install-sh missing +install diff --git a/main.cpp b/main.cpp index 2dd8048..6dc5465 100644 --- a/main.cpp +++ b/main.cpp @@ -9,8 +9,9 @@ using namespace std; -static const unsigned int bytes_in_block = 0x800; -static const char * dbname = "/var/lib/backups/backups.db"; +static unsigned int bytes_in_block; +static const char * dbname_in = getenv("backupdbin"); +static const char * dbname_out = getenv("backupdbout"); unsigned long long read_time( istream &i ) { string date_string; @@ -133,6 +134,17 @@ void delete_objects( ITER begin, const ITER &end ) { } int main() { + + // Check to make sure required env variables are set + if(getenv("backupdbin") == NULL || getenv("backupdbout") == NULL || getenv("blocksize") == NULL || getenv("availsizemb") == NULL) + { + cerr << "Required environment variables are not set. Exiting." << endl; + return 1; + } + + // Setup our bytes_in_block value + bytes_in_block = atoll(getenv("blocksize")); + // Get the date on stdin unsigned long long now = read_time( cin ); @@ -141,7 +153,7 @@ int main() { populate_set( cin, current ); file_set backed_up; - ifstream db( dbname ); + ifstream db( dbname_in ); if( db && db.good() ) { populate_set( db, backed_up ); } @@ -183,8 +195,8 @@ int main() { sort( backups_s.rbegin(), backups_s.rend(), FileData::sizecmp ); file_set final; - unsigned long long space = 0x100000000ULL; - + unsigned long long space = atoll(getenv("availsizemb")) * 1048576ull; + insert_iterator final_i( final, final.begin() ); // Copy files over until full or out of files @@ -217,10 +229,15 @@ int main() { unsigned long long total_blocks, total_bytes; sizes( final.begin(), final.end(), total_blocks, total_bytes ); + // Track how many disks there are remaining to be burned + unsigned long long disks_remaining = 0; + if(modified_bytes || added_bytes) + disks_remaining = (unsigned long long)ceil(static_cast(modified_bytes+added_bytes)/(atoll(getenv("availsizemb"))*1048576ull))-1; + updateLastBackupDate( final.begin(), final.end(), now ); // Write the 'current' list to the dbfile - ofstream dbout( dbname ); + ofstream dbout( dbname_out ); copy( current.begin(), current.end(), ostream_iterator( dbout ) ); // Write the 'final' list to stdout @@ -232,7 +249,8 @@ int main() { cerr << " Added Bytes: " << added_bytes << endl; cerr << " Added Blocks: " << added_blocks << endl; cerr << " Modified Bytes: " << modified_bytes << endl; - cerr << " Modified Blocks: " << modified_blocks << endl << endl; + cerr << " Modified Blocks: " << modified_blocks << endl; + cerr << " Disks Remaining: " << disks_remaining << endl << endl; cerr << "Will be backed up..." << endl; cerr << " Essential Bytes: " << essential_bytes << endl; diff --git a/rescue.tgz b/rescue.tgz deleted file mode 100644 index 178bca5..0000000 Binary files a/rescue.tgz and /dev/null differ diff --git a/scripts/burn-imgs.sh b/scripts/burn-imgs.sh index bffc5e9..a1a6483 100755 --- a/scripts/burn-imgs.sh +++ b/scripts/burn-imgs.sh @@ -13,8 +13,8 @@ cronstopstart="/etc/init.d/cron" # If the noburn file is there then don't burn. [ -f "$noburnfile" ] && exit 0 -# Discover disk images by looking for .img.md5sum files in $imagedir -imgmd5=$(ls $imagedir/*.img.md5sum 2>/dev/null | head -n 1) +# Discover disk images by looking for .iso.md5sum files in $imagedir +imgmd5=$(ls $imagedir/*.iso.md5sum 2>/dev/null | head -n 1) # If we didn't find an non-empty file then exit gracefully [ -z "$imgmd5" ] && exit 0 diff --git a/scripts/config.sh b/scripts/config.sh index c3b4a26..ff58479 100755 --- a/scripts/config.sh +++ b/scripts/config.sh @@ -5,7 +5,6 @@ datadir="/var/lib/backups" tmpdir="/dev/shm/backups" imagedir="/backup/imgs" currentfiles="$tmpdir/files.db" -backupdb="$datadir/backups.db" backups="$tmpdir/backup-list.db" statusfile="$imagedir/backup-status.txt" lastbackupfile="$imagedir/lastbackup" @@ -13,6 +12,13 @@ dev="/dev/dvdrw" sdev="ATA:1,0,0" noburnfile="$imagedir/noburn" +# These are exported so lsbackups can have access to them +export backupdbin="$datadir/backups.db" +export backupdbout="$datadir/backups.db.tmp" +export imagesizemb=4440 +export availsizemb=4096 +export blocksize=2048 + backupdirs=" /etc /home diff --git a/scripts/pack-image.sh b/scripts/pack-image.sh index 9a06f71..fd1e8bc 100755 --- a/scripts/pack-image.sh +++ b/scripts/pack-image.sh @@ -10,9 +10,14 @@ export PATH=$scriptsdir:/bin:/usr/bin:/sbin:/usr/sbin # source the system specific configuration [ -f /etc/lsbackups.conf ] && . /etc/lsbackups.conf +# process command line arguments +case "$1" in + -s) simulate=1;; +esac + # file locations and other values today=$(date +%Y%m%d%H%M%S) -isoimage="$imagedir/$today.img" +isoimage="$imagedir/$today.iso" isomountdir="$isoimage.mnt" restorescript="$scriptsdir/restore.sh" @@ -29,11 +34,11 @@ then fi echo "-> Creating the iso image in $isoimage" -dd of=$isoimage bs=1M count=0 seek=4440 +dd of=$isoimage bs=1M count=0 seek=$imagesizemb [ $? != 0 ] && err "dd failed to create $isoimage" -mke2fs -b 2048 -F $isoimage +mke2fs -b $blocksize -F $isoimage if [ $? != 0 ] then @@ -41,6 +46,14 @@ then err "Unable to create the iso image: $isoimage" fi +e2label $isoimage $today + +if [ $? != 0 ] +then + rm -rf $isomountdir $isoimage + err "Unable to label the iso image: $isoimage" +fi + echo "-> Mounting the iso image" mount -t ext2 -o loop $isoimage $isomountdir if [ $? != 0 ] @@ -57,16 +70,20 @@ echo "-> Running find to get the status of files" { for type in d f l; do findformat="$type %#m %u %g %s %CY%Cm%Cd%CH%CM%CS 0 %p\0" - if [ -z $excludeddirs ] + if [ -z "$excludedirs" ] then find $backupdirs -type $type -printf "$findformat" else - regex=`echo $excludedirs | sed -e 's/ /.*\\\\|/g'` - regex=`echo "'\($regex.*\)'"` - find $backupdirs -type $type -o -regex $regex -prune -o -printf "$findformat" + echo $excludedirs | sed -e 's/ /\n/g' > $tmpdir/excluded + find $backupdirs -type $type -printf "$findformat" | grep -z -v -f $tmpdir/excluded fi done -} > $currentfiles +} > $currentfiles + +if [ ! -z $simulate ] +then + backupdbin=$backupdbout +fi echo "-> Determining list of files to backup with lsbackups" { @@ -75,20 +92,31 @@ echo "-> Determining list of files to backup with lsbackups" cat $currentfiles } | lsbackups > $backups 2>$statusfile +if [ ! -z $simulate ] +then + umount $isomountdir + rm -rf $isomountdir $isoimage + cat $statusfile + echo "-> Simulated backup complete! Backup database: $backupdbout" + exit; +fi + echo "-> Running rsync to pack the image" rsyncopts="-W -H -S -l -p -t -g -o -0 --files-from=- --stats --progress" cat $backups | rsync $rsyncopts / $isomountdir if [ $? != 0 ] then umount $isomountdir - rm -rf $isomountdir $isoimage + rm -rf $isomountdir $isoimage $backupdbout err "Unable to rsync to pack the image" fi echo "-> Copying over database and status file" -cp $statusfile $backupdb $restorescript $isomountdir +cp $backupdbout $isomountdir/$(basename $backupdbin) +[ $? != 0 ] && err "Unable to copy the database to $isomountdir" -[ $? != 0 ] && err "Unable to copy the database and status file" +cp $statusfile $restorescript $isomountdir +[ $? != 0 ] && err "Unable to copy the status file to $isomountdir" echo "-> Unmounting image" umount $isomountdir @@ -104,4 +132,8 @@ cat $statusfile | mailx -s "DVD image available to burn - $today" $mailto echo $today > $lastbackupfile +echo "-> Moving new database to $backupdbin" +mv $backupdbout $backupdbin +[ $? != 0 ] && err "Unable to move backupdb: $backupdbout to $backupdbin" +