Submit enhancement from Michael Zimmerman to allow --suffix to be used
authorDavid Dykstra <dwd@samba.org>
Thu, 9 May 2002 21:44:46 +0000 (21:44 +0000)
committerDavid Dykstra <dwd@samba.org>
Thu, 9 May 2002 21:44:46 +0000 (21:44 +0000)
with --backup-dir.

NEWS
backup.c
options.c
rsync.yo

diff --git a/NEWS b/NEWS
index c9d6d24..e255d69 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,12 @@
 rsync changes since last release
 
+  ENHANCEMENTS:
+
+    * The --delete-after option now implies --delete. (Wayne Davison)
+
+    * The --suffix option can now be used with --backup-dir. (Michael
+      Zimmerman)
+
   BUG FIXES:
   
     * Fix "forward name lookup failed" errors on AIX 4.3.3.  (John
@@ -15,8 +22,6 @@ rsync changes since last release
 
       http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=62489
 
-    * The --delete-after option now implies --delete.
-
   INTERNAL:
 
     * Many code cleanups and improved internal documentation.  (Martin 
index a30e7ff..0fb6373 100644 (file)
--- a/backup.c
+++ b/backup.c
@@ -21,6 +21,7 @@
 #include "rsync.h"
 
 extern int verbose;
+extern int suffix_specified;
 extern char *backup_suffix;
 extern char *backup_dir;
 
@@ -203,12 +204,17 @@ static int keep_backup(char *fname)
        if (!file) return 1;
 
         /* make a complete pathname for backup file */
-        if (strlen(backup_dir) + strlen(fname) > (MAXPATHLEN - 1)) {
+        if (strlen(backup_dir) + strlen(fname) + 
+               (suffix_specified ? strlen(backup_suffix) : 0) > (MAXPATHLEN - 1)) {
                 rprintf (FERROR, "keep_backup filename too long\n");
                 return 0;
         }
 
-        snprintf(keep_name, sizeof (keep_name), "%s/%s", backup_dir, fname);
+       if (suffix_specified) {
+               snprintf(keep_name, sizeof (keep_name), "%s/%s%s", backup_dir, fname, backup_suffix);
+               } else {
+               snprintf(keep_name, sizeof (keep_name), "%s/%s", backup_dir, fname);
+               }
 
 
 #ifdef HAVE_MKNOD
index 1652aed..d43399b 100644 (file)
--- a/options.c
+++ b/options.c
@@ -102,6 +102,7 @@ int no_detach = 0;
 
 int write_batch = 0;
 int read_batch = 0;
+int suffix_specified = 0;
 
 char *backup_suffix = BACKUP_SUFFIX;
 char *tmpdir = NULL;
@@ -296,7 +297,7 @@ enum {OPT_VERSION = 1000, OPT_SUFFIX, OPT_SENDER, OPT_SERVER, OPT_EXCLUDE,
 static struct poptOption long_options[] = {
   /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
   {"version",          0,  POPT_ARG_NONE,   0,             OPT_VERSION, 0, 0},
-  {"suffix",           0,  POPT_ARG_STRING, &backup_suffix,    0, 0, 0 },
+  {"suffix",           0,  POPT_ARG_STRING, &backup_suffix,    OPT_SUFFIX, 0, 0 },
   {"rsync-path",       0,  POPT_ARG_STRING, &rsync_path,       0, 0, 0 },
   {"password-file",    0,  POPT_ARG_STRING, &password_file,    0, 0, 0 },
   {"ignore-times",    'I', POPT_ARG_NONE,   &ignore_times , 0, 0, 0 },
@@ -470,6 +471,13 @@ int parse_arguments(int *argc, const char ***argv, int frommain)
                         print_rsync_version(FINFO);
                        exit_cleanup(0);
                        
+               case OPT_SUFFIX:
+                        /* The value has already been set by popt, but
+                         * we need to remember that a suffix was specified
+                         * in case a backup-directory is used. */
+                        suffix_specified = 1;
+                       break;
+                       
                case OPT_MODIFY_WINDOW:
                         /* The value has already been set by popt, but
                          * we need to remember that we're using a
index b8880f2..5b9c677 100644 (file)
--- a/rsync.yo
+++ b/rsync.yo
@@ -226,7 +226,7 @@ verb(
  -R, --relative              use relative path names
  -b, --backup                make backups (default ~ suffix)
      --backup-dir            make backups into this directory
-     --suffix=SUFFIX         override backup suffix
+     --suffix=SUFFIX         define backup suffix
  -u, --update                update only (don't overwrite newer files)
  -l, --links                 copy symlinks as symlinks
  -L, --copy-links            copy the referent of symlinks
@@ -374,10 +374,15 @@ control the backup suffix using the --suffix option.
 
 dit(bf(--backup-dir=DIR)) In combination with the --backup option, this
 tells rsync to store all backups in the specified directory. This is
-very useful for incremental backups.
+very useful for incremental backups.  You can additionally
+specify a backup suffix using the --suffix option
+(otherwise the files backed up in the specified directory
+will keep their original filenames).
 
 dit(bf(--suffix=SUFFIX)) This option allows you to override the default
 backup suffix used with the -b option. The default is a ~.
+If --backup-dir and --suffix are both specified,
+the SUFFIX is appended to the filename even in the backup directory.
 
 dit(bf(-u, --update)) This forces rsync to skip any files for which the
 destination file already exists and has a date later than the source