Sample Header Ad - 728x90

Is there a tool to "recursively" move/rename a directory (with conflicts/merging)?

0 votes
1 answer
60 views
Imagine I want to move (rename) a directory tree /var/lib/postgres/data to /var/lib/postgres/data.old:
/var/lib/postgres
└── data
    ├── base
    │   ├── 16390
    │   │   └── 
    │   └── 
    │       └── 
    ├── global
    │   └── 
    ├── pg_wal
    │   ├── 
    │   ├── archive_status
    │   └── summaries
    ├── 
    └── postmaster.pid
Typically, it's a single rename() syscall away and a single command away: mv data data.old. However, imagine that there is an active mountpoint somewhere in that directory tree, e.g., pg_wal is a different filesystem:
$ findmnt

├─/var/lib/postgres                           stank/data/stratofortress/PostgreSQL                              zfs       rw,noatime,xattr,posixacl,casesensitive
│ └─/var/lib/postgres/data/pg_wal             stank/data/stratofortress/PostgreSQL/pg_wal                       zfs       rw,noatime,xattr,posixacl,case-sensitive
Alternatively, imagine that the target name (data.old) already exists and some branches of the directory tree are already created (because they are mountpoints, in the same vein as above). ~~In both these cases~~ In the latter case, mv will refuse to do anything. Performing a deep copy with something like a cp -a is prohibitively expensive, and reflinks are unavailable for reasons that are outside of the scope of this question. --- Is there a tool that can perform an optimal "recursive move", iteratively descending into parts of the source hierarchy for each subtree that cannot be renamed wholesale, up to individual files (finally falling back to making a copy of each individual file if needed)? **NB: I'm looking for a generalized solution that can be extended to any number of subtrees and conflicts, i.e., mv data/* -t data.old; mv data/pg_wal/* -t data.old/pg_wal is not a solution. In other words, please do not infer any constraints or special cases from the example above.**
Asked by intelfx (5699 rep)
Jan 20, 2025, 08:45 PM
Last activity: Jan 22, 2025, 06:09 AM