# Keeping 2 buckets sort of in sync

**URL:** <https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426>\
**Category:** Help and Support\
**Created:** [April 6, 2020, 5:29pm UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426 "2020-04-06T17:29:33Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![scsuperlight](https://forum.rclone.org/letter_avatar_proxy/v4/letter/s/e9a140/32.png) [@scsuperlight](https://forum.rclone.org/u/scsuperlight)\
**Post date:** [April 6, 2020, 5:29pm UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426/1 "2020-04-06T17:29:33Z")

</div>

Hi guys, I'm writing to 2 buckets with the same data, one has a retention policy of 90 days, the other a year... I can't just sync them, I need anything lost with one write to fill back into the other, any suggestions? I plan on running a cron once a day to sort it out. It's a few petabytes of data, so anything I do as far as scanning is pretty slow. Thanks to the community for being so helpful, you've helped me through a few hurdles so far :o)

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [April 8, 2020, 5:03pm UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426/2 "2020-04-08T17:03:00Z")

</div>

I don't quite understand what you are trying to achieve.

Is it

- when an object is missing from the 90 day bucket
- you copy it from the 1 year bucket?

How do you determine when an object is missing? Why not set the retention policy of both to 1 year? I've probably mis-understood something!

---

<div class="post-metadata">

**Author:** ![scsuperlight](https://forum.rclone.org/letter_avatar_proxy/v4/letter/s/e9a140/32.png) [@scsuperlight](https://forum.rclone.org/u/scsuperlight)\
**Post date:** [April 8, 2020, 5:21pm UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426/3 "2020-04-08T17:21:58Z")

</div>

Hey Nick, so we have an outside collection unit trying to post videos to these redundant buckets, each large bucket has 1 petabyte of data, the small one has 90 days of data (still a lot of data). Trying to figure out how to maybe rsync between these guys, without removing anything from large or small buckets. Thanks for the suggestions!

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [April 8, 2020, 7:43pm UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426/4 "2020-04-08T19:43:28Z")

</div>

Is this the work flow

- outside collection unit posts videos to 90-day bucket and 1-year bucket
- you want to make sure that two copies of each video that they posted exist (maybe one of the uploads failed)
- you don't want to copy all the data from the 1-year bucket into the 90-day bucket

Is that it?

Can you describe also how the files are arranged? Are they in dated folders for instance or arranged some other way?

---

<div class="post-metadata">

**Author:** ![scsuperlight](https://forum.rclone.org/letter_avatar_proxy/v4/letter/s/e9a140/32.png) [@scsuperlight](https://forum.rclone.org/u/scsuperlight)\
**Post date:** [April 9, 2020, 3:36pm UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426/5 "2020-04-09T15:36:23Z")

</div>

Hey Nick, yes, that is the flow, the files are stored with a timestamp + a bit of other info, it should be very rare that we can't write to both, but we have to cover just in case... possible to rsync on a date parameter? I could just go back 1 or 2 days and run it on a cron, just throwing some ideas around, I appreciate any suggestions. Thanks

---

<div class="post-metadata">

**Author:** ![scsuperlight](https://forum.rclone.org/letter_avatar_proxy/v4/letter/s/e9a140/32.png) [@scsuperlight](https://forum.rclone.org/u/scsuperlight)\
**Post date:** [April 9, 2020, 3:43pm UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426/6 "2020-04-09T15:43:31Z")

</div>

All files are just stored in the root, no concept of directories in S3, just metadata, so we just make sure they are all unique, here is an example: 23332\_1004-1-1-1-6-1-1\_1575241148.579.ts

---

<div class="post-metadata">

**Author:** ![calisro](https://forum.rclone.org/user_avatar/forum.rclone.org/calisro/32/3130_2.png) [@calisro](https://forum.rclone.org/u/calisro)\
**Post date:** [April 9, 2020, 4:01pm UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426/7 "2020-04-09T16:01:37Z")

</div>

Do they always have the same names of the files? If so, isn't it just a matter of limiting the age of the files checked?

You could just do a copy across each (both ways a\_b and b\_a) ignoring the actual file dates. You could use a checksum (--checksum) which would be really expensive or a file size and name (--ignore-times). You could also limit the copy to the lower of your retention which is less than 90 days (--max-age). Maybe 60 days back? or even less.

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [April 9, 2020, 4:06pm UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426/8 "2020-04-09T16:06:30Z")

</div>

> [@scsuperlight](#):
>
> All files are just stored in the root, no concept of directories in S3, just metadata

S3 has no concept of directories, but rclone can use the directory separators to break syncs down into smaller pieces.

> [@scsuperlight](#):
>
> yes, that is the flow, the files are stored with a timestamp + a bit of other info, it should be very rare that we can't write to both, but we have to cover just in case..

OK!

> [@scsuperlight](#):
>
> possible to rsync on a date parameter? I could just go back 1 or 2 days and run it on a cron,

That would be possible...

Are the files uploaded with rclone? I'll assume not

Let's say you've got the two buckets called `little` and `large`

What you could do is something like this

```
rclone copy --use-server-modtime --max-age 2d --checksum --no-traverse s3:little s3:large

```

What that will do is find files uploaded in the last 2d (`--max-age` and `--use-server-modtime`) and copy them from little to large if the `--checksum` does not match. `--no-traverse` will ensure it doesn't list the destination - it will only do HEAD requests to check the objects are there.

You'd then run it again reversing `little` and `large`.

This will, alas, have to list the large bucket - I can't see a way around that without writing a specialised script which knows how your file names work.

If you want to see what files would be checked then do

```
rclone ls --use-server-modtime --max-age 2d s3:little

```

If you are using two buckets in the same region then rclone will use a server side copy. However if you have two different remotes, say s3east: and s3:west then rclone will use your bandwidth to do the copying.

I hope that helps!

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [April 9, 2020, 4:12pm UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426/9 "2020-04-09T16:12:21Z")

</div>

Thinking more, I'd probably use `--size-only` instead of `--checksum` above as it will be slightly more efficient and you are only really interested in file presence or not.

In fact what would you want to happen if the file was present in both places but different?

---

<div class="post-metadata">

**Author:** ![scsuperlight](https://forum.rclone.org/letter_avatar_proxy/v4/letter/s/e9a140/32.png) [@scsuperlight](https://forum.rclone.org/u/scsuperlight)\
**Post date:** [April 9, 2020, 4:34pm UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426/10 "2020-04-09T16:34:50Z")

</div>

thanks guys! the files should be the same in both, they come from the same source, let me digest this and try some things out. I've been uploading files for 4 months with rclone, production will start writing them in a bit, so it will be a mix of both for a bit.

much appreciated :o)

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [April 10, 2020, 11:33am UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426/11 "2020-04-10T11:33:50Z")

</div>

Good luck! Let us know if you need any more help.

---

<div class="post-metadata">

**Author:** ![scsuperlight](https://forum.rclone.org/letter_avatar_proxy/v4/letter/s/e9a140/32.png) [@scsuperlight](https://forum.rclone.org/u/scsuperlight)\
**Post date:** [April 14, 2020, 5:15pm UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426/12 "2020-04-14T17:15:42Z")

</div>

Hi guys, the copy works great, glad I can specify how far to look back, I have 1 last question... If I have the same file name in both buckets, but the sizes are different (we had issues writing the whole video to one bucket), is there a way to only overwrite a file if it is bigger?

I've been testing with this scenario, both names are the same:

Small bucket - xxxx.ts = 17.75 MB

Large bucket - xxxx.ts = 15.6 MB

hopefully something easy here. In my tests I'm clobbering the bigger file with the smaller one.

Thanks!

---

<div class="post-metadata">

**Author:** ![calisro](https://forum.rclone.org/user_avatar/forum.rclone.org/calisro/32/3130_2.png) [@calisro](https://forum.rclone.org/u/calisro)\
**Post date:** [April 14, 2020, 5:37pm UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426/13 "2020-04-14T17:37:05Z")

</div>

There isn't an option to keep the bigger. The source will overwrite the destination if its different. You could specify min/max size but that isn't what you're looking for.

---

<div class="post-metadata">

**Author:** ![scsuperlight](https://forum.rclone.org/letter_avatar_proxy/v4/letter/s/e9a140/32.png) [@scsuperlight](https://forum.rclone.org/u/scsuperlight)\
**Post date:** [April 14, 2020, 5:39pm UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426/14 "2020-04-14T17:39:21Z")

</div>

Thanks, I was going through all the flags and was wondering if I just missed it. I'll see what i can do with min/max, thanks for the suggestions.

---

<div class="post-metadata">

**Author:** ![calisro](https://forum.rclone.org/user_avatar/forum.rclone.org/calisro/32/3130_2.png) [@calisro](https://forum.rclone.org/u/calisro)\
**Post date:** [April 14, 2020, 5:47pm UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426/15 "2020-04-14T17:47:07Z")

</div>

Might be best to script that though. You could identify differing sizes using dry-run and parse.

```
# rclone copy h g --size-only --dry-run -vv 2>&1 | grep "Sizes differ"
2020/04/14 13:46:17 DEBUG : 1: Sizes differ (src 2 vs dst 7)

```

Then perhaps compare those sizes and transfer just the one to the right location depending on that check. That output will give both sizes and you can then process it based on the output (omit from the copy and manually adjust it)

Better yet, use check? but you won't get the sizes of the files output so dry-run with copy might be better!!

```
# rclone check h g -vv 2>&1 | grep "Sizes differ"
2020/04/14 13:50:16 ERROR : 1: Sizes differ
```

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [April 15, 2020, 11:47am UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426/16 "2020-04-15T11:47:54Z")

</div>

You could do your syncs as above with `--ignore-existing` which will sort out all the missing files first but leave the differing sizes alone.

Then doing the `rclone copy -vv --dry-run little: large:` and grepping out the `Sizes differ` as @calisro suggested would be one way to go.

---

<div class="post-metadata">

**Author:** ![scsuperlight](https://forum.rclone.org/letter_avatar_proxy/v4/letter/s/e9a140/32.png) [@scsuperlight](https://forum.rclone.org/u/scsuperlight)\
**Post date:** [April 16, 2020, 6:25pm UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426/17 "2020-04-16T18:25:16Z")

</div>

Thanks Nick, I like the --ignore-existing approach, this should be a rare situation, but at least if 1 was good I wouldn't clobber it, and can recover it if needed.

appreciate the suggestions guys!

---

<div class="post-metadata">

**Author:** ![scsuperlight](https://forum.rclone.org/letter_avatar_proxy/v4/letter/s/e9a140/32.png) [@scsuperlight](https://forum.rclone.org/u/scsuperlight)\
**Post date:** [April 20, 2020, 5:10pm UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426/18 "2020-04-20T17:10:15Z")

</div>

The compare works great, I think I'll just run this on a cron and send an email to investigate if there ever are any, thanks again guys!

---

<div class="post-metadata">

**Author:** ![system](https://forum.rclone.org/uploads/default/original/2X/3/39ad3235f6ffec76ccd0c81616bd55697b4c300d.png) [@system](https://forum.rclone.org/u/system)\
**Post date:** [June 20, 2020, 1:15pm UTC](https://forum.rclone.org/t/keeping-2-buckets-sort-of-in-sync/15426/19 "2020-06-20T13:15:50Z")

</div>

Closed on June 20, 2020, 1:15pm UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
