# Import the relevant PTS classes and modules from pts.eagle import config from pts.eagle.database import Database from pts.eagle.database import backup from pts.eagle.skirtrun import SkirtRun # ----------------------------------------------------------------- cosma_prefix = "[email protected]:" # ----------------------------------------------------------------- # copy the cosma database to obiwan so we have a backup and we can open it locally print "--> Copying database from cosma to obiwan backup area..." cosma_database_path = os.path.join(config.cosma["database_path"], "SKIRT-runs.db") backup_database_path = os.path.join(config.backup_path, "cosma_SKIRT-runs_backup_"+config.timestamp()+".db") subprocess.call(("rsync", "-htz", cosma_prefix+cosma_database_path, backup_database_path)) # extract records for all completed SKIRT-runs from the local copy of the cosma database db = Database(backup_database_path) records = db.select("runstatus = 'completed'") db.close() print "--> Cosma has {} completed SKIRT-runs".format(len(records)) # backup and open the local database backup() db = Database() # remove SKIRT-runs that have been archived from the do-list records = filter(lambda record: db.select("runid="+str(record['runid']))[0]['runstatus']!='archived', records) print "--> .. of which {} have not yet been archived".format(len(records))
# create the archives if os.path.isfile(inzip): os.remove(inzip) error = subprocess.call(("zip", "-rj", inzip, indir)) if error: raise ValueError("Error while zipping the in directory: " + str(error)) if os.path.isfile(outzip): os.remove(outzip) error = subprocess.call(("zip", "-rj", outzip, outdir)) if error: raise ValueError("Error while zipping the out directory: " + str(error)) # copy the archives offsite print "--> Copying archives for SKIRT-run {}...".format(runid) timestamp = config.timestamp() archdir = os.path.join(archive_path, "g-{0:04}".format(runid // 1000)) archin = os.path.join(archdir, "r-{0:04}-{1:03}_in_{2}.zip".format(runid // 1000, runid % 1000, timestamp)) archout = os.path.join(archdir, "r-{0:04}-{1:03}_out_{2}.zip".format(runid // 1000, runid % 1000, timestamp)) if not os.path.isdir(archdir): os.makedirs(archdir) error = subprocess.call(("cp", "-v", inzip, archin)) if error: raise ValueError("Error while copying the in archive: " + str(error)) error = subprocess.call(("cp", "-v", outzip, archout)) if error: raise ValueError("Error while copying the out archive: " + str(error)) # update the runstatus in the database db.updatestatus((runid,), "archived") db.commit()
from pts.eagle.database import backup from pts.eagle.skirtrun import SkirtRun # ----------------------------------------------------------------- cosma_prefix = "[email protected]:" # ----------------------------------------------------------------- # copy the cosma database to obiwan so we have a backup and we can open it locally print "--> Copying database from cosma to obiwan backup area..." cosma_database_path = os.path.join(config.cosma["database_path"], "SKIRT-runs.db") backup_database_path = os.path.join( config.backup_path, "cosma_SKIRT-runs_backup_" + config.timestamp() + ".db") subprocess.call(("rsync", "-htz", cosma_prefix + cosma_database_path, backup_database_path)) # extract records for all completed SKIRT-runs from the local copy of the cosma database db = Database(backup_database_path) records = db.select("runstatus = 'completed'") db.close() print "--> Cosma has {} completed SKIRT-runs".format(len(records)) # backup and open the local database backup() db = Database() # remove SKIRT-runs that have been archived from the do-list records = filter(
infofile.close() # create the archives if os.path.isfile(inzip): os.remove(inzip) error = subprocess.call(("zip", "-rj", inzip, indir)) if error: raise ValueError("Error while zipping the in directory: " + str(error)) if os.path.isfile(outzip): os.remove(outzip) error = subprocess.call(("zip", "-rj", outzip, outdir)) if error: raise ValueError("Error while zipping the out directory: " + str(error)) # copy the archives offsite print "--> Copying archives for SKIRT-run {}...".format(runid) timestamp = config.timestamp() archdir = os.path.join(archive_path, "g-{0:04}".format(runid // 1000)) archin = os.path.join( archdir, "r-{0:04}-{1:03}_in_{2}.zip".format(runid // 1000, runid % 1000, timestamp)) archout = os.path.join( archdir, "r-{0:04}-{1:03}_out_{2}.zip".format(runid // 1000, runid % 1000, timestamp)) if not os.path.isdir(archdir): os.makedirs(archdir) error = subprocess.call(("cp", "-v", inzip, archin)) if error: raise ValueError("Error while copying the in archive: " + str(error)) error = subprocess.call(("cp", "-v", outzip, archout)) if error: raise ValueError("Error while copying the out archive: " + str(error))