#!/usr/bin/perl -W

#
# PROJECT
#          Hinode/EIS
# PURPOSE
#          Perl script which runs on remote planner's machine.
#          Makes a tarball of;
#              $HOME/planning_db/timeline_db
#              $HOME/eis_cpt_properties.txt
# CATEGORY
#          EIS Timeline Planning/Remote Planning
# WRITTEN
#          John Rainnie 14-Oct-2008
# HISTORY
#          v0.0 JAR 9-Sep-2008
#               Blah
#

use Env qw(HOME);

print "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";


$a_dir = "$HOME/eis_rp_tldb";
print "Archive directory: $a_dir\n";
#########################################################################
#
# Refresh archive directory
#
#########################################################################
# Check whether $HOME/eis_rp_tldb directory exists - remove it if so!
if(-e $a_dir) {
    print "Archive exists: deleting...\n";
    system("/bin/rm -rf $a_dir");
}

# Re-create the eis_rp_archive directory
print "Archive created\n";
system("/bin/mkdir $a_dir");

#########################################################################
#
# Timeline Databases
#
#########################################################################
# Copy all of $HOME/planing_db/timeline_db into eis_rp_archive
print "Archive adding timeline database to archive\n";
system("/bin/cp -rp $HOME/planning_db/timeline_db $a_dir");

#########################################################################
#
# CPT Properties File
#
#########################################################################
print "Archive adding CPT properties file: $HOME/eis_cpt_properties.txt\n";
system("/bin/cp $HOME/eis_cpt_properties.txt   $a_dir");

#########################################################################
#
# Tar up the directory here!
#
print "Created tarball: $HOME/eis_rp_tldb.tar.gz\n";
system("cd $HOME && tar cfz $HOME/eis_rp_tldb.tar.gz eis_rp_tldb/");
#########################################################################

print "Finished archiving\n";
print "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
#########################################################################
