        } 
  
        if (!db_get_job_record(jcr, jcr->db, &jcr->jr)) {
+Index: src/dird/ua_purge.c
+===================================================================
+--- src/dird/ua_purge.c	(revision 8203)
++++ src/dird/ua_purge.c	(working copy)
+@@ -360,6 +360,57 @@
+ }
+ 
+ /*
++ * Change the type of the next copy job to backup.
++ * We need to upgrade the next copy of a normal job,
++ * and also upgrade the next copy when the normal job
++ * already have been purged.
++ *
++ *   JobId: 1   PriorJobId: 0    (original)
++ *   JobId: 2   PriorJobId: 1    (first copy)
++ *   JobId: 3   PriorJobId: 1    (second copy)
++ *
++ *   JobId: 2   PriorJobId: 1    (first copy, now regular backup)
++ *   JobId: 3   PriorJobId: 1    (second copy)
++ *
++ *  => Search through PriorJobId in jobid and
++ *                    PriorJobId in PriorJobId (jobid)
++ */
++void upgrade_copies(UAContext *ua, char *jobs)
++{
++   POOL_MEM query(PM_MESSAGE);
++   
++   db_lock(ua->db);
++   /* Do it in two times for mysql */
++   Mmsg(query, "CREATE TEMPORARY TABLE cpy_tmp AS "
++                  "SELECT MIN(JobId) AS JobId FROM Job "     /* Choose the oldest job */
++                   "WHERE Type='%c' "
++                     "AND ( PriorJobId IN (%s) "
++                         "OR "
++                          " PriorJobId IN ( "
++                             "SELECT PriorJobId "
++                               "FROM Job "
++                              "WHERE JobId IN (%s) "
++                               " AND Type='B' "
++                            ") "
++                         ") "
++                   "GROUP BY PriorJobId ",           /* one result per copy */
++        JT_JOB_COPY, jobs, jobs);
++   db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL);
++
++   /* Now upgrade first copy to Backup */
++   Mmsg(query, "UPDATE Job SET Type='B' "           /* JT_JOB_COPY => JT_BACKUP  */
++                "WHERE JobId IN ( SELECT JobId FROM cpy_tmp )");
++
++   db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL);
++
++   Mmsg(query, "DROP TABLE cpy_tmp");
++   db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL);
++
++   db_unlock(ua->db);
++   Dmsg1(00, "Upgrade copies Log sql=%s\n", query.c_str());
++}
++
++/*
+  * Remove all records from catalog for a list of JobIds
+  */
+ void purge_jobs_from_catalog(UAContext *ua, char *jobs)
+@@ -377,13 +428,15 @@
+    db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL);
+    Dmsg1(050, "Delete Log sql=%s\n", query.c_str());
+ 
++   upgrade_copies(ua, jobs);
++
+    /* Now remove the Job record itself */
+    Mmsg(query, "DELETE FROM Job WHERE JobId IN (%s)", jobs);
+    db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL);
++
+    Dmsg1(050, "Delete Job sql=%s\n", query.c_str());
+ }
+ 
+-
+ void purge_files_from_volume(UAContext *ua, MEDIA_DBR *mr )
+ {} /* ***FIXME*** implement */
+ 
+Index: src/dird/ua_restore.c
+===================================================================
+--- src/dird/ua_restore.c	(revision 8203)
++++ src/dird/ua_restore.c	(working copy)
+@@ -444,6 +444,7 @@
+       "add_suffix",   /* 17 */
+       "regexwhere",   /* 18 */
+       "restoreclient", /* 19 */
++      "copies",        /* 20 */
+       NULL
+    };
+ 
+@@ -1138,9 +1139,10 @@
+    bool ok = false;
+    FILESET_DBR fsr;
+    CLIENT_DBR cr;
++   POOL_MEM other_filter(PM_MESSAGE);
++   POOL_MEM temp_filter(PM_MESSAGE);
+    char fileset_name[MAX_NAME_LENGTH];
+    char ed1[50], ed2[50];
+-   char pool_select[MAX_NAME_LENGTH];
+    int i;
+ 
+    /* Create temp tables */
+@@ -1196,23 +1198,32 @@
+    }
+ 
+    /* If Pool specified, add PoolId specification */
+-   pool_select[0] = 0;
+    if (rx->pool) {
+       POOL_DBR pr;
+       memset(&pr, 0, sizeof(pr));
+       bstrncpy(pr.Name, rx->pool->name(), sizeof(pr.Name));
+       if (db_get_pool_record(ua->jcr, ua->db, &pr)) {
+-         bsnprintf(pool_select, sizeof(pool_select), "AND Media.PoolId=%s ", 
+-            edit_int64(pr.PoolId, ed1));
++         Mmsg(other_filter, " AND Media.PoolId=%s ", 
++              edit_int64(pr.PoolId, ed1));
+       } else {
+          ua->warning_msg(_("Pool \"%s\" not found, using any pool.\n"), pr.Name);
+       }
+    }
++   /* include copies or not in job selection */
++   if (find_arg(ua, NT_("copies")) > 0) {
++      Mmsg(temp_filter, "%s AND Job.Type IN ('%c', '%c') ", 
++           other_filter.c_str(), (char)JT_BACKUP, (char)JT_JOB_COPY);
++   } else {
++      Mmsg(temp_filter, "%s AND Job.Type = '%c' ", other_filter.c_str(),
++           (char)JT_BACKUP);
++   }
++   pm_strcpy(other_filter, temp_filter.c_str());
+ 
+    /* Find JobId of last Full backup for this client, fileset */
+    edit_int64(cr.ClientId, ed1);
+    Mmsg(rx->query, uar_last_full, ed1, ed1, date, fsr.FileSet,
+-         pool_select);
++        other_filter.c_str());
++   Dmsg1(0, "sql=%s\n", rx->query);
+    if (!db_sql_query(ua->db, rx->query, NULL, NULL)) {
+       ua->error_msg("%s\n", db_strerror(ua->db));
+       goto bail_out;
+@@ -1238,12 +1249,13 @@
+ 
+    /* Now find most recent Differental Job after Full save, if any */
+    Mmsg(rx->query, uar_dif, edit_uint64(rx->JobTDate, ed1), date,
+-        edit_int64(cr.ClientId, ed2), fsr.FileSet, pool_select);
++        edit_int64(cr.ClientId, ed2), fsr.FileSet, other_filter.c_str());
+    if (!db_sql_query(ua->db, rx->query, NULL, NULL)) {
+       ua->warning_msg("%s\n", db_strerror(ua->db));
+    }
+    /* Now update JobTDate to lock onto Differental, if any */
+    rx->JobTDate = 0;
++   Dmsg1(0, "sql=%s\n", rx->query);
+    if (!db_sql_query(ua->db, uar_sel_all_temp, last_full_handler, (void *)rx)) {
+       ua->warning_msg("%s\n", db_strerror(ua->db));
+    }
+@@ -1254,7 +1266,8 @@
+ 
+    /* Now find all Incremental Jobs after Full/dif save */
+    Mmsg(rx->query, uar_inc, edit_uint64(rx->JobTDate, ed1), date,
+-        edit_int64(cr.ClientId, ed2), fsr.FileSet, pool_select);
++        edit_int64(cr.ClientId, ed2), fsr.FileSet, other_filter.c_str());
++   Dmsg1(0, "sql=%s\n", rx->query);
+    if (!db_sql_query(ua->db, rx->query, NULL, NULL)) {
+       ua->warning_msg("%s\n", db_strerror(ua->db));
+    }
+@@ -1267,6 +1280,8 @@
+    }
+ 
+    if (rx->JobIds[0] != 0) {
++      /* Display a list of all copies */
++      db_list_copies_records(ua->jcr, ua->db, 0, rx->JobIds, prtit, ua, HORZ_LIST);
+       /* Display a list of Jobs selected for this restore */
+       db_list_sql_query(ua->jcr, ua->db, uar_list_temp, prtit, ua, 1, HORZ_LIST);
+       ok = true;
 Index: src/dird/ua_cmds.c
 ===================================================================
---- src/dird/ua_cmds.c	(revision 8163)
+--- src/dird/ua_cmds.c	(revision 8203)
 +++ src/dird/ua_cmds.c	(working copy)
 @@ -123,7 +123,7 @@
   { NT_("exit"),       quit_cmd,      _("exit = quit"),                                false},

 
Index: src/lib/util.c
===================================================================
--- src/lib/util.c	(revision 8163)
+++ src/lib/util.c	(working copy)
@@ -361,6 +361,9 @@
    case JT_COPY:

Index: src/dird/ua_output.c
===================================================================
--- src/dird/ua_output.c	(revision 8203)
+++ src/dird/ua_output.c	(working copy)
@@ -223,6 +223,7 @@
  *  list clients        - list clients
  *  list nextvol job=xx  - list the next vol to be used by job
  *  list nextvolume job=xx - same as above.
+ *  list copies jobid=x,y,z
  *
  */
 
@@ -454,6 +455,19 @@
             }
          }
          list_nextvol(ua, n);
+      } else if (strcasecmp(ua->argk[i], NT_("copies")) == 0) {
+         char *jobids=NULL;
+         uint32_t limit=0;
+         for (j=i+1; j<ua->argc; j++) {
+            if (strcasecmp(ua->argk[j], NT_("jobid")) == 0 && ua->argv[j]) {
+               if (is_a_number_list(ua->argv[j])) {
+                  jobids = ua->argv[j];
+               }
+            } else if (strcasecmp(ua->argk[j], NT_("limit")) == 0 && ua->argv[j]) {
+               limit = atoi(ua->argv[j]);
+            } 
+         }
+         db_list_copies_records(ua->jcr,ua->db,limit,jobids,prtit,ua,llist);
       } else if (strcasecmp(ua->argk[i], NT_("limit")) == 0
                  || strcasecmp(ua->argk[i], NT_("days")) == 0) {
          /* Ignore it */
Index: src/dird/migrate.c
===================================================================
--- src/dird/migrate.c	(revision 8203)
+++ src/dird/migrate.c	(working copy)
@@ -1158,13 +1158,17 @@
       /*
