From: Carl N Baldwin Date: Tue, 25 Oct 2005 17:01:11 +0000 (-0600) Subject: Determine date in the scripts rather than c++ X-Git-Tag: release-0.4~68 X-Git-Url: http://git.pippins.net/embedvideo/.git/%27%20%20%20%20.%20%24GLOBALS%5B%27phpgw%27%5D-%3Elink%28%27inc/jquery/%22%22.%24thumbnail.%22/%7Blink_participation%7D?a=commitdiff_plain;h=9f95453a2b3a4ffde7c553b93a6cac6eec618958;p=backups%2F.git Determine date in the scripts rather than c++ --- diff --git a/main.cpp b/main.cpp index c7ae387..a551850 100644 --- a/main.cpp +++ b/main.cpp @@ -12,18 +12,17 @@ using namespace std; static const unsigned int bytes_in_block = 0x800; static const char * dbname = "/var/lib/backups/backups.db"; -unsigned long long current_time() { - unsigned long long rc = 0; - time_t now_tt = time( 0 ); - tm *now = localtime( &now_tt ); - rc += ( now->tm_year + 1900ULL ) * 10000000000ULL; - rc += ( now->tm_mon + 1ULL ) * 100000000ULL; - rc += now->tm_mday * 1000000ULL; - rc += now->tm_hour * 10000ULL; - rc += now->tm_min * 100ULL; - rc += now->tm_sec; - - return rc; +unsigned long long read_time( istream &i ) { + string date_string; + + int c; + // Todo, don't use char_traits directly here + for( c = i.get(); 0 != c && char_traits::eof() != c; c = i.get() ) { + date_string.push_back( c ); + } + if( char_traits::eof() == c ) { i.setstate( ios_base::eofbit ); } + + return atoll( date_string.c_str() ); } template @@ -137,6 +136,9 @@ void delete_objects( ITER begin, const ITER &end ) { } int main() { + // Get the date on stdin + unsigned long long now = read_time( cin ); + // Parse the list of current files on stdin file_set current; populate_set( cin, current ); @@ -216,7 +218,6 @@ int main() { unsigned long long total_blocks, total_bytes; sizes( final.begin(), final.end(), total_blocks, total_bytes ); - unsigned long long now = current_time(); updateLastBackupDate( final.begin(), final.end(), now ); // Write the 'current' list to the dbfile diff --git a/scripts/drive.sh b/scripts/drive.sh index 6ea91a6..a75c20f 100755 --- a/scripts/drive.sh +++ b/scripts/drive.sh @@ -6,6 +6,7 @@ bindir="$scriptsdir/../build" export PATH=$scriptsdir:$bindir:$PATH # file locations and other values +today=$(date +%Y%m%d%H%M%S) datadir="/var/lib/backups" tmpdir="/dev/shm/backups" currentfiles="$tmpdir/files.db" @@ -36,7 +37,11 @@ echo "Running find to get the status of files" find-cmd.sh /home > $currentfiles echo "Determining list of files to backup with lsbackups" -cat $currentfiles | lsbackups > $backups 2>$statusfile +{ + # lsbackups expects the current date followed by a null before the list of files + printf "$today\0" + cat $currentfiles +} | lsbackups > $backups 2>$statusfile echo "Running rsync to pack the image" cat $backups | rsync-cmd.sh $isomountdir