How Does backup-directory-alist Interact with version-control and backup-by-copying When Restoring Centralized Backups?
0 reputation · 20 Mar 2024, 10:51 UTC
0 reputation · 20 Mar 2024, 10:51 UTC
When backup-directory-alist redirects backups to a central location, Emacs transforms original filenames to avoid collisions, while version-control and backup-by-copying further influence naming and filesystem metadata. The documentation describes each variable independently, but their combined effect on restoration is not specified: a user must locate the correct transformed backup, decide whether to copy or rename it back, and account for permission or timestamp changes introduced by backup-by-copying. No built-in command automates this lookup or verifies that the restored file matches the intended version.
Given that backups in the central directory lack checksums and may be pruned by kept-new-versions or kept-old-versions, a reliable restoration workflow requires manual correlation of transformed names with original paths and an external integrity check.
backup-directory-alist and version-control are both active?backup-by-copying preserve the original file's permissions and timestamps on the restored copy, or does it inherit the backup file's metadata?30775 reputation · 20 Mar 2024, 22:04 UTC
When backup-directory-alist is used to centralize backups, Emacs transforms the original absolute path into a single filename by replacing directory separators (/) with exclamation marks (!). The interaction with version-control and backup-by-copying determines the final filename and the metadata of the resulting file during restoration.
The transformed naming scheme follows a strict pattern: [backup-directory] + [!transformed-path] + [version-suffix]. If version-control is active (set to t or numbered), Emacs appends a numbered suffix to allow multiple versions. If version-control is nil, only a single backup is kept with a trailing tilde.
| Configuration | Example Path | Transformed Backup Name |
|---|---|---|
version-control nil |
/home/user/doc.txt |
!home!user!doc.txt~ |
version-control t |
/home/user/doc.txt |
!home!user!doc.txt.~1~, ...~2~ |
The backup-by-copying variable affects the creation of the backup, not the restoration process. When enabled, Emacs copies the file instead of renaming it, meaning the backup file inherits the original file's permissions and modification time at the moment the backup was created.
During restoration, Emacs provides no automated tool to "undo" this. If you manually copy a backup back to the original location (e.g., via cp), the restored file inherits the metadata of the backup file, not the metadata of the original file as it existed before the backup was taken. To preserve the backup's timestamps during restoration, use cp -p.
Since there is no built-in command to map a current buffer back to its centralized backup, follow these steps to identify the correct version:
/ in the absolute path of your file with !.ls -t ~/.emacs.d/backups/!home!user!project!file.c*version-control is numbered, the highest number corresponds to the latest save.stat before copying it back to the original path.This behavior assumes a Unix-like filesystem. On Windows, drive letters are typically handled by replacing the colon (e.g., C: becomes !C!). Note that kept-new-versions and kept-old-versions prune files during the save process; if a version has been pruned, it cannot be recovered via Emacs.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.