Score:0

SSH access to remote 'dynamic' directory

it flag

short version

I'd like to synchronize a remote directory, whose name changes. Something like (not working!):

rsync -a '[email protected]:~/.zfs/snashots/$(ls -d Automatic-* | tail -1)/foo'  ~/foo

longer version / background

I have an internet accessible hard drive (Hetzner Storage Box), which regularly creates ZFS snapshots. I can access the snapshots within the /.zfs/snapshots directory. For every snapshot there is a subdirectory named after a pattern like Automatic-<timestamp>:

$ ls /.zfs/snapshots
Automatic-2021-10-01T00-25-22   Automatic-2021-12-01T00-23-14   Automatic-2022-02-01T00-21-38

Each of this folders contain a frozen state of my files at the time of snapshot creation. I would like to regularly mirror the contents of the latest folder to my home server, because this folder contains the latest 'frozen' state of my files. Because the timestamp pattern is sortable, the latest folder could for example be queried by following command:

$ ls -d Automatic-* | tail -1
Automatic-2022-04-01T00-24-16

Is there any possibility to tell rsync how to get the 'latest' remote source directory?

I haven't tried the command substitution from my example above - but I think that wouldn't work with rsync. However I have tried to create a symbolic link (ln -s '/path/to/$(ls -d Automatic-* | tail -1)/foo' /target). However the ln command resolves the path on creation and not on access.

Any idea?

Score:0
it flag

I found one possible solution for my needs. I wrote a script, which queries the required folder in advance of the sync:

#!/bin/bash
LATEST_SNAPSHOT=$(ssh xxx.your-storagebox.de 'ls .zfs/snapshot/' | tail -1)
rsync -a "xxx.your-storagebox.de:.zfs/snapshot/${LATEST_SNAPSHOT}" /target
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.