From 6fa75d791efc5530f4fe9ffc4d21b8866d1543aa Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 24 Feb 2008 13:42:21 +0000 Subject: [PATCH] Implement first cut of Copy Job git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6479 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/cats/sql_cmds.c | 22 ++++++++++++++++++++++ bacula/src/cats/sql_cmds.h | 3 ++- bacula/src/dird/dird_conf.c | 3 ++- bacula/src/dird/job.c | 9 ++++++--- bacula/src/dird/migrate.c | 7 +++---- bacula/src/dird/msgchan.c | 6 +++--- bacula/src/dird/ua_prune.c | 3 +++ bacula/src/dird/ua_run.c | 16 +++++++++++++--- bacula/src/lib/jcr.c | 2 +- bacula/src/stored/job.c | 2 +- bacula/technotes-2.3 | 1 + 11 files changed, 57 insertions(+), 17 deletions(-) diff --git a/bacula/src/cats/sql_cmds.c b/bacula/src/cats/sql_cmds.c index 6dcf3ef1c9..eb6463259e 100644 --- a/bacula/src/cats/sql_cmds.c +++ b/bacula/src/cats/sql_cmds.c @@ -173,6 +173,19 @@ const char *select_migrate_del = "AND Job.ClientId=%s " "AND Job.Type='g')"; +/* + * Select Jobs from the DelCandidates table. + * This is the list of Jobs to delete for an Copy Job. + */ +const char *select_copy_del = + "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles " + "FROM Job,DelCandidates " + "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus!='T') OR " + "(Job.JobTDate>%s " + "AND Job.ClientId=%s " + "AND Job.Type='C')"; + + #else /* Faster way */ const char *select_backup_del = @@ -233,6 +246,15 @@ const char *select_migrate_del = "AND Job.ClientId=%s " "AND Job.Type='g')"; +const char *select_copy_del = + "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles " + "FROM Job,DelCandidates " + "WHERE (Job.JobId=DelCandidates.JobId AND DelCandidates.JobStatus!='T') OR " + "(Job.JobTDate>%s " + "AND Job.ClientId=%s " + "AND Job.Type='C')"; + + #endif /* ======= ua_restore.c */ diff --git a/bacula/src/cats/sql_cmds.h b/bacula/src/cats/sql_cmds.h index 5d4678728e..c9cf8e5de2 100644 --- a/bacula/src/cats/sql_cmds.h +++ b/bacula/src/cats/sql_cmds.h @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. + Copyright (C) 2000-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -37,6 +37,7 @@ extern const char CATS_IMP_EXP *select_verify_del; extern const char CATS_IMP_EXP *select_restore_del; extern const char CATS_IMP_EXP *select_admin_del; extern const char CATS_IMP_EXP *select_migrate_del; +extern const char CATS_IMP_EXP *select_copy_del; extern const char CATS_IMP_EXP *select_job; extern const char CATS_IMP_EXP *count_select_job; extern const char CATS_IMP_EXP *del_File; diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index 27de4b1f12..71eab38175 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -461,6 +461,7 @@ struct s_jt jobtypes[] = { {"verify", JT_VERIFY}, {"restore", JT_RESTORE}, {"migrate", JT_MIGRATE}, + {"copy", JT_COPY}, {NULL, 0} }; @@ -623,7 +624,7 @@ void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fm if (res->res_job.JobType == JT_BACKUP) { sendit(sock, _(" Accurate=%d\n"), res->res_job.accurate); } - if (res->res_job.JobType == JT_MIGRATE) { + if (res->res_job.JobType == JT_MIGRATE || res->res_job.JobType == JT_COPY) { sendit(sock, _(" SelectionType=%d\n"), res->res_job.selection_type); } if (res->res_job.client) { diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index ea8a41bc8f..77700bf54e 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -147,7 +147,7 @@ bool setup_job(JCR *jcr) pm_strcpy(jcr->pool_source, _("unknown source")); } Dmsg2(500, "pool=%s (From %s)\n", jcr->pool->name(), jcr->pool_source); - if (jcr->JobType == JT_MIGRATE) { + if (jcr->JobType == JT_MIGRATE || jcr->JobType == JT_COPY) { if (!jcr->rpool_source) { jcr->rpool_source = get_pool_memory(PM_MESSAGE); pm_strcpy(jcr->rpool_source, _("unknown source")); @@ -202,6 +202,7 @@ bool setup_job(JCR *jcr) admin_cleanup(jcr, JS_ErrorTerminated); } break; + case JT_COPY: case JT_MIGRATE: if (!do_migration_init(jcr)) { migration_cleanup(jcr, JS_ErrorTerminated); @@ -315,9 +316,8 @@ static void *job_thread(void *arg) admin_cleanup(jcr, JS_ErrorTerminated); } break; - case JT_MIGRATE: case JT_COPY: - case JT_ARCHIVE: + case JT_MIGRATE: if (do_migration(jcr)) { do_autoprune(jcr); } else { @@ -956,6 +956,7 @@ void set_jcr_defaults(JCR *jcr, JOB *job) case JT_RESTORE: jcr->JobLevel = L_NONE; break; + case JT_COPY: case JT_MIGRATE: if (!jcr->rpool_source) { jcr->rpool_source = get_pool_memory(PM_MESSAGE); @@ -1046,6 +1047,7 @@ void copy_rwstorage(JCR *jcr, alist *storage, const char *where) switch(jcr->JobType) { case JT_RESTORE: case JT_VERIFY: + case JT_COPY: case JT_MIGRATE: copy_rstorage(jcr, storage, where); break; @@ -1066,6 +1068,7 @@ void set_rwstorage(JCR *jcr, USTORE *store) switch(jcr->JobType) { case JT_RESTORE: case JT_VERIFY: + case JT_COPY: case JT_MIGRATE: set_rstorage(jcr, store); break; diff --git a/bacula/src/dird/migrate.c b/bacula/src/dird/migrate.c index ed08899552..1808f403b7 100644 --- a/bacula/src/dird/migrate.c +++ b/bacula/src/dird/migrate.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2004-2007 Free Software Foundation Europe e.V. + Copyright (C) 2004-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -1067,7 +1067,7 @@ void migration_cleanup(JCR *jcr, int TermCode) db_sql_query(mig_jcr->db, query.c_str(), NULL, NULL); /* Now mark the previous job as migrated if it terminated normally */ - if (jcr->JobStatus == JS_Terminated) { + if (jcr->JobType == JT_MIGRATE && jcr->JobStatus == JS_Terminated) { Mmsg(query, "UPDATE Job SET Type='%c' WHERE JobId=%s", (char)JT_MIGRATED_JOB, edit_uint64(jcr->previous_jr.JobId, ec1)); db_sql_query(mig_jcr->db, query.c_str(), NULL, NULL); @@ -1079,7 +1079,6 @@ void migration_cleanup(JCR *jcr, int TermCode) set_jcr_job_status(jcr, JS_ErrorTerminated); } - update_bootstrap_file(mig_jcr); if (!db_get_job_volume_names(mig_jcr, mig_jcr->db, mig_jcr->jr.JobId, &mig_jcr->VolumeName)) { @@ -1143,7 +1142,7 @@ void migration_cleanup(JCR *jcr, int TermCode) break; } } else { - if (jcr->previous_jr.JobId != 0) { + if (jcr->JobType == JT_MIGRATE && jcr->previous_jr.JobId != 0) { /* Mark previous job as migrated */ Mmsg(query, "UPDATE Job SET Type='%c' WHERE JobId=%s", (char)JT_MIGRATED_JOB, edit_uint64(jcr->previous_jr.JobId, ec1)); diff --git a/bacula/src/dird/msgchan.c b/bacula/src/dird/msgchan.c index 43d859aa28..c1d5280ea2 100644 --- a/bacula/src/dird/msgchan.c +++ b/bacula/src/dird/msgchan.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2000-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -218,8 +218,8 @@ bool start_storage_daemon_job(JCR *jcr, alist *rstore, alist *wstore) */ /* Do read side of storage daemon */ if (ok && rstore) { - /* For the moment, only migrate has rpool */ - if (jcr->JobType == JT_MIGRATE) { + /* For the moment, only migrate and copy have rpool */ + if (jcr->JobType == JT_MIGRATE || jcr->JobType == JT_COPY) { pm_strcpy(pool_type, jcr->rpool->pool_type); pm_strcpy(pool_name, jcr->rpool->name()); } else { diff --git a/bacula/src/dird/ua_prune.c b/bacula/src/dird/ua_prune.c index 2083fc53dc..764ae2af1a 100644 --- a/bacula/src/dird/ua_prune.c +++ b/bacula/src/dird/ua_prune.c @@ -350,6 +350,9 @@ int prune_jobs(UAContext *ua, CLIENT *client, int JobType) case JT_ADMIN: Mmsg(query, select_admin_del, ed1, ed2); break; + case JT_COPY: + Mmsg(query, select_copy_del, ed1, ed2); + break; case JT_MIGRATE: Mmsg(query, select_migrate_del, ed1, ed2); break; diff --git a/bacula/src/dird/ua_run.c b/bacula/src/dird/ua_run.c index 41af09f17c..ec201ab598 100644 --- a/bacula/src/dird/ua_run.c +++ b/bacula/src/dird/ua_run.c @@ -205,7 +205,7 @@ try_again: /* If pool changed, update migration write storage */ - if (jcr->JobType == JT_MIGRATE) { + if (jcr->JobType == JT_MIGRATE || jcr->JobType == JT_COPY) { if (!set_migration_wstorage(jcr, rc.pool)) { goto bail_out; } @@ -276,6 +276,7 @@ try_again: add_prompt(ua, _("When")); /* 5 */ add_prompt(ua, _("Priority")); /* 6 */ if (jcr->JobType == JT_BACKUP || + jcr->JobType == JT_COPY || jcr->JobType == JT_MIGRATE || jcr->JobType == JT_VERIFY) { add_prompt(ua, _("Pool")); /* 7 */ @@ -357,6 +358,7 @@ try_again: case 7: /* Pool or Bootstrap depending on JobType */ if (jcr->JobType == JT_BACKUP || + jcr->JobType == JT_COPY || jcr->JobType == JT_MIGRATE || jcr->JobType == JT_VERIFY) { /* Pool */ rc.pool = select_pool_resource(ua); @@ -852,10 +854,17 @@ static bool display_job_parameters(UAContext *ua, JCR *jcr, JOB *job, const char jcr->JobPriority); } break; + case JT_COPY: case JT_MIGRATE: + char *prt_type; + if (jcr->JobType == JT_COPY) { + prt_type = _("Run Copy job\n"); + } else { + prt_type = _("Run Migration job\n"); + } jcr->JobLevel = L_FULL; /* default level */ if (ua->api) ua->signal(BNET_RUN_CMD); - ua->send_msg(_("Run Migration job\n" + ua->send_msg("%s" "JobName: %s\n" "Bootstrap: %s\n" "Client: %s\n" @@ -866,7 +875,8 @@ static bool display_job_parameters(UAContext *ua, JCR *jcr, JOB *job, const char "JobId: %s\n" "When: %s\n" "Catalog: %s\n" - "Priority: %d\n"), + "Priority: %d\n", + prt_type, job->name(), NPRT(jcr->RestoreBootstrap), jcr->client->name(), diff --git a/bacula/src/lib/jcr.c b/bacula/src/lib/jcr.c index b193fcbfcc..80e404d7a0 100644 --- a/bacula/src/lib/jcr.c +++ b/bacula/src/lib/jcr.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2000-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. diff --git a/bacula/src/stored/job.c b/bacula/src/stored/job.c index c3fc476925..733f20b042 100644 --- a/bacula/src/stored/job.c +++ b/bacula/src/stored/job.c @@ -171,8 +171,8 @@ bool run_cmd(JCR *jcr) Dmsg1(200, "Run_cmd: %s\n", jcr->dir_bsock->msg); /* The following jobs don't need the FD */ switch (jcr->JobType) { - case JT_MIGRATE: case JT_COPY: + case JT_MIGRATE: case JT_ARCHIVE: jcr->authenticated = true; do_mac(jcr); diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index 55e43ac0cc..f2cf96157f 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -2,6 +2,7 @@ General: 24Feb08 +kes Implement first cut of Copy Job. kes Implement Catalog in Pool resource. It overrides catalog specified in the Client resource. 22Feb08 -- 2.39.5