带符号链接及其内容的版本控制 linux 文件夹
Versioning linux folder with symlinks and them content
我的用例是服务器上的版本控制应用程序更改,因为有时我需要在更新之前或配置更改之前回滚以前的版本。
这是我的内容列表:
dasper@debian:/usr/share/otrs$
drwxr-xr-x 6 root root 4096 Sep 18 16:56 .
drwxr-xr-x 109 root root 4096 Sep 18 13:13 ..
lrwxrwxrwx 1 root root 21 May 9 11:06 ARCHIVE -> /var/lib/otrs/ARCHIVE
drwxr-xr-x 4 root root 4096 Sep 11 15:53 bin
-rwx------ 1 root root 212450 Sep 18 16:06 .etckeeper
-rw-r--r-- 1 root root 1125 Jan 11 2019 .fetchmailrc.dist
drwx------ 8 root root 4096 Sep 18 16:06 .git
-rw-r--r-- 1 root root 932 Sep 18 15:40 .gitignore
drwxr-xr-x 9 root root 4096 Sep 11 15:53 Kernel
-rw-r--r-- 1 root root 104 Jan 12 2019 RELEASE
drwxr-xr-x 7 root root 4096 Sep 11 15:53 scripts
-rw-r--r-- 1 root root 0 Sep 18 15:36 testfile.txt
lrwxrwxrwx 1 root root 13 May 9 11:06 var -> /var/lib/otrs
我正在尝试 etckeeper 在包管理器进行一些更改后自动提交,但是 git 默认情况下只会创建空文件夹 var/
和 ARCHIVE/
。
我正在尝试子模块,但后来我不知道符号链接文件夹 (git add .
) 的变化,子模块内容不能导致符号链接文件夹。
我最大的问题是如何将这些文件夹存储在 git 中以及如何以相同的结构 clone/checkout。
解决方案简单明了,我希望 :)
apt-get install etckeeper
为存储库创建目录。这是安装到其他磁盘
mkdir /BACKUP
cd /BACKUP
初始化 git 存储库并将工作树设置为根 /。现在我可以跟踪整个系统的变化,而不仅仅是 /etc
git init
git config --path core.worktree /
我的.git忽略里面的/BACKUP:
# Ignore everything ~ whitelist
*
# But descend into directories
!*/
# Add /usr/share/otrs/ - main directory
!/usr/share/otrs/**
# Add /var/lib/otrs - symlink # Add /usr/share/otrs/var -> /var/lib/otrs
!/var/lib/otrs/**
...
# Add myself
!/.gitignore
# Add etckeeper staff
!/etc/.etckeeper/**
在 /etc/etckeeper/etckeeper.conf
末尾添加新行,存储库路径:
ETCKEEPER_DIR=/BACKUP
最后,删除安装后由etckeeper初始化的未使用的repo:
cd /etc
rm -rf .git
rm .gitignore
现在您可以进行第一次初始提交:etckeeper commit
我的用例是服务器上的版本控制应用程序更改,因为有时我需要在更新之前或配置更改之前回滚以前的版本。
这是我的内容列表:
dasper@debian:/usr/share/otrs$
drwxr-xr-x 6 root root 4096 Sep 18 16:56 .
drwxr-xr-x 109 root root 4096 Sep 18 13:13 ..
lrwxrwxrwx 1 root root 21 May 9 11:06 ARCHIVE -> /var/lib/otrs/ARCHIVE
drwxr-xr-x 4 root root 4096 Sep 11 15:53 bin
-rwx------ 1 root root 212450 Sep 18 16:06 .etckeeper
-rw-r--r-- 1 root root 1125 Jan 11 2019 .fetchmailrc.dist
drwx------ 8 root root 4096 Sep 18 16:06 .git
-rw-r--r-- 1 root root 932 Sep 18 15:40 .gitignore
drwxr-xr-x 9 root root 4096 Sep 11 15:53 Kernel
-rw-r--r-- 1 root root 104 Jan 12 2019 RELEASE
drwxr-xr-x 7 root root 4096 Sep 11 15:53 scripts
-rw-r--r-- 1 root root 0 Sep 18 15:36 testfile.txt
lrwxrwxrwx 1 root root 13 May 9 11:06 var -> /var/lib/otrs
我正在尝试 etckeeper 在包管理器进行一些更改后自动提交,但是 git 默认情况下只会创建空文件夹 var/
和 ARCHIVE/
。
我正在尝试子模块,但后来我不知道符号链接文件夹 (git add .
) 的变化,子模块内容不能导致符号链接文件夹。
我最大的问题是如何将这些文件夹存储在 git 中以及如何以相同的结构 clone/checkout。
解决方案简单明了,我希望 :)
apt-get install etckeeper
为存储库创建目录。这是安装到其他磁盘
mkdir /BACKUP
cd /BACKUP
初始化 git 存储库并将工作树设置为根 /。现在我可以跟踪整个系统的变化,而不仅仅是 /etc
git init
git config --path core.worktree /
我的.git忽略里面的/BACKUP:
# Ignore everything ~ whitelist
*
# But descend into directories
!*/
# Add /usr/share/otrs/ - main directory
!/usr/share/otrs/**
# Add /var/lib/otrs - symlink # Add /usr/share/otrs/var -> /var/lib/otrs
!/var/lib/otrs/**
...
# Add myself
!/.gitignore
# Add etckeeper staff
!/etc/.etckeeper/**
在 /etc/etckeeper/etckeeper.conf
末尾添加新行,存储库路径:
ETCKEEPER_DIR=/BACKUP
最后,删除安装后由etckeeper初始化的未使用的repo:
cd /etc
rm -rf .git
rm .gitignore
现在您可以进行第一次初始提交:etckeeper commit