On Fri, 4 May 2001, Benoit Langevin wrote:
> I am new using rsync, and it got some advantage, but do you know if I
> do the equivalent of a move with rsync. I have a case where I need to
> delete the remote after retrieving it.
I had the same need, so I wrote a patch for rsync. It turned out to
be very trivial to get it to move any file that it created/updated (it
does not remove any identical files or any directories). Attached is
a diff of the changes for rsync 2.4.6. See if you like it.
..wayne..
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: options.c
@@ -73,6 +73,7 @@
int modify_window=0;
#endif
int blocking_io=0;
+int move_files=0;
char *backup_suffix = BACKUP_SUFFIX;
char *tmpdir = NULL;
@@ -188,7 +189,7 @@
OPT_LOG_FORMAT, OPT_PASSWORD_FILE, OPT_SIZE_ONLY, OPT_ADDRESS,
OPT_DELETE_AFTER, OPT_EXISTING, OPT_MAX_DELETE, OPT_BACKUP_DIR,
OPT_IGNORE_ERRORS, OPT_BWLIMIT, OPT_BLOCKING_IO,
- OPT_MODIFY_WINDOW};
+ OPT_MODIFY_WINDOW, OPT_MOVE_FILES};
static char *short_options = "oblLWHpguDCtcahvqrRIxnSe:B:T:zP";
@@ -255,6 +256,7 @@
{"address", 1, 0, OPT_ADDRESS},
{"max-delete", 1, 0, OPT_MAX_DELETE},
{"backup-dir", 1, 0, OPT_BACKUP_DIR},
+ {"move-files", 0, 0, OPT_MOVE_FILES},
{0,0,0,0}};
@@ -596,6 +598,10 @@
backup_dir = optarg;
break;
+ case OPT_MOVE_FILES:
+ move_files = 1;
+ break;
+
default:
slprintf(err_buf,sizeof(err_buf),"unrecognised option\n");
return 0;
@@ -768,6 +774,8 @@
args[ac++] = compare_dest;
}
+ if (move_files)
+ args[ac++] = "--move-files";
*argc = ac;
}
Index: sender.c
@@ -26,7 +26,7 @@
extern int io_error;
extern int dry_run;
extern int am_server;
-
+extern int move_files;
/*
receive the checksums for a buffer
@@ -212,6 +212,8 @@
if (verbose > 2)
rprintf(FINFO,"sender finished %s\n",fname);
+ if (move_files && do_unlink(fname) == 0 && verbose > 1)
+ rprintf(FINFO,"sender removed %s\n",fname);
}
if (verbose > 2)
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---