From 759ac87019791378c4a97b541e7cdf1349dd4c69 Mon Sep 17 00:00:00 2001 From: David Dykstra Date: Thu, 9 May 2002 21:44:46 +0000 Subject: [PATCH] Submit enhancement from Michael Zimmerman to allow --suffix to be used with --backup-dir. --- NEWS | 9 +++++++-- backup.c | 10 ++++++++-- options.c | 10 +++++++++- rsync.yo | 9 +++++++-- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index c9d6d240..e255d69d 100644 --- 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 diff --git a/backup.c b/backup.c index a30e7ff8..0fb6373a 100644 --- 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 diff --git a/options.c b/options.c index 1652aed2..d43399bf 100644 --- 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 diff --git a/rsync.yo b/rsync.yo index b8880f2e..5b9c677b 100644 --- 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 -- 2.34.1