具有“版本化”文件名的联合文件系统?

atr*_*ent 5 linux filesystems

你知道是否有一个用于 GNU/Linux 的联合 fs 也显示名称略有不同的“影子”文件?IE 如果我有两个 fs,例如:

root1
+dir1
+dir2
 +file1
 +file2
 +file3

root2
+dir1
+dir2
 +file1
 +file2
 +file4
Run Code Online (Sandbox Code Playgroud)

由此产生的“联合” fs 应该导致:

unioned
+dir1
+dir2
 +file1
 +file1.1
 +file2
 +file2.1
 +file3
Run Code Online (Sandbox Code Playgroud)

这样就可以快速检查“联合” fs 之间的差异

好像 UnionFS 和 Aufs 不提供这个选项

谢谢

gla*_*len 1

另一种方法是使用git-annex

首先,我们将设置测试文件:

#!/bin/bash 
# faster than /dev/urandom
randfile='openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt < /dev/zero'
dd='dd bs=1M count=5 iflag=fullblock'

for I in 1 2
do
  mkdir root$I
  cd root$I
  for J in 1 2
  do
    mkdir dir$J
    if [ -e dir2 ]
    then
      cd dir2
      eval $randfile | eval $dd of=file1
      eval $randfile | eval $dd of=file2
      if [ `pwd | grep root1` ]; then
        eval $randfile | eval $dd of=file3
      elif [ `pwd | grep root2` ]; then
        eval $randfile | eval $dd of=file4
      fi
      cd ..
    fi
  done
  cd ..
done
Run Code Online (Sandbox Code Playgroud)

这将创建目录,其中包含包含随机数据的二进制文件。此时文件是:

user@host$ find root? -path '*/.git*' -prune -o -print | sort -n 
root1
root1/dir1
root1/dir2
root1/dir2/file1
root1/dir2/file2
root1/dir2/file3
root2
root2/dir1
root2/dir2
root2/dir2/file1
root2/dir2/file2
root2/dir2/file4
Run Code Online (Sandbox Code Playgroud)

现在,我们初始化存储库并执行同步:

cd root1
  git init
  git annex init 'root1'
  git remote add root2 ../root2
  #git annex direct
  git annex add .
  git commit -a -m 'Files added.'
cd ..
cd root2
  git init
  git annex init 'root1'
  git remote add root1 ../root1
  #git annex direct
  git annex add .
  git commit -a -m 'Files added.'
cd ..
mkdir unioned
cd unioned
  git init
  git annex init 'unioned'
  git remote add root1 ../root1
  git remote add root2 ../root2
  git annex add . 
  git commit -a -m 'Files added.'
  git annex sync
cd ..
Run Code Online (Sandbox Code Playgroud)

此时,内容为unioned/

user@host$ find root? unioned -path '*/.git*' -prune -o -print | sort -n
root1
root1/dir1
root1/dir2
root1/dir2/file1
root1/dir2/file2
root1/dir2/file3
root2
root2/dir1
root2/dir2
root2/dir2/file1
root2/dir2/file2
root2/dir2/file4
unioned
unioned/dir2
unioned/dir2/file1
unioned/dir2/file1.variant-065a
unioned/dir2/file1.variant-a33e
unioned/dir2/file2
unioned/dir2/file2.variant-08f3
unioned/dir2/file2.variant-75c4
unioned/dir2/file3
unioned/dir2/file4
Run Code Online (Sandbox Code Playgroud)

链接*.variant-*回不同存储库中的不同文件。此外,unioned在我们进行 . 之前,仍然不包含任何数据git annex get。目前,git annex list显示文件所在位置和/或来源:

user@host$ cd unioned; git annex list
here
|root1
||root2
|||web
||||
__X_ dir2/file1.variant-065a
_X__ dir2/file1.variant-a33e
__X_ dir2/file2.variant-08f3
_X__ dir2/file2.variant-75c4
_X__ dir2/file3
__X_ dir2/file4
Run Code Online (Sandbox Code Playgroud)

更长形式的替代方案是git annex whereis. 最后,要解决冲突并从内部传播合并unioned/dir2

cd unioned/dir2
git annex get # retrieve the actual content
git annex unlock # unlock the files - replace the symlinks with the actual repofiles
rm file1
git mv file1.variant-065a file1
git rm -f file1.variant-a33e
rm file2
git mv file2.variant-75c4 file2
git rm -f file2.variant-08f3
git annex add . # "commits" the changes, converts files back into symlinks
git annex sync  # propagates the changes back to the other repos
Run Code Online (Sandbox Code Playgroud)

其产量:

git annex sync
commit  ok
pull root2 
ok
pull root1 
ok
push root2 
Counting objects: 61, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (26/26), done.
Writing objects: 100% (37/37), 2.67 KiB | 0 bytes/s, done.
Total 37 (delta 14), reused 0 (delta 0)
To ../root2
   e5df80f..720b34b  git-annex -> synced/git-annex
   b055385..ad8c5c2  master -> synced/master
ok
push root1 
Counting objects: 61, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (26/26), done.
Writing objects: 100% (37/37), 2.67 KiB | 0 bytes/s, done.
Total 37 (delta 14), reused 0 (delta 0)
To ../root1
   e5df80f..720b34b  git-annex -> synced/git-annex
   b055385..ad8c5c2  master -> synced/master
ok
Run Code Online (Sandbox Code Playgroud)

最后,agit annex list显示同步后这些文件所在的位置:该unioned/目录具有从上述不同服务器中选择的所有文件的副本。


git-annex还有一种直接模式,可以直接在文件系统上运行,而不使用符号链接。

将其设置为在远程计算机上使用是使用标准 git 通过 ssh 设置遥控器的问题,但其行为如下所述:http ://git-annex.branchable.com/walkthrough/using_ssh_remotes/

gitannex的整体演练位于这里:http ://git-annex.branchable.com/walkthrough/