Etckeeper: Difference between revisions
use explicit paths in example |
m Text replacement - "<(\/?)source" to "<$1syntaxhighlight" Tags: Mobile edit Mobile web edit |
||
| (6 intermediate revisions by one other user not shown) | |||
| Line 1: | Line 1: | ||
== Intro == | == Intro == | ||
Etckeeper is a great tool created by Joey Hess to use your favorite VCS to keep track of what's going on in <code>/etc</code>. | [https://etckeeper.branchable.com/ Etckeeper] (also at https://github.com/joeyh/etckeeper) is a great tool created by Joey Hess to use your favorite VCS to keep track of what's going on in <code>/etc</code>. | ||
== TLDR == | |||
<syntaxhighlight lang="bash"> | |||
sudo su - | |||
apt-get install etckeeper | |||
cd /etc/ | |||
# change VCS to 'git' by commenting out bzr; and uncomment git | |||
vim etckeeper/etckeeper.conf | |||
# add the contents below to etckeeper/commit.d/20mirror-outside-files | |||
# and make it executable | |||
chmod a+x etckeeper/commit.d/20mirror-outside-files | |||
# create your repo | |||
etckeeper init | |||
# commit your files | |||
etckeeper commit | |||
# now everything should just happen automagically anytime something in etc changes | |||
</syntaxhighlight> | |||
== Extending etckeeper == | == Extending etckeeper == | ||
Say you want to keep track of changes to the configuration directory or file of some app. You also want to make it automatic and painless. Etckeeper leverages the commit hook in git to create that mirror. So, for example, the most critical aspect of your [[wiki]] is the <code>LocalSettings.php</code> configuration file. You don't want to commit the file to the version control of the project because it would expose sensitive data. etckeeper can be used to track changes to any file on the filesystem, but it's done discretely on the host. | Say you want to keep track of changes to the configuration directory or file of some app. You also want to make it automatic and painless. Etckeeper leverages the commit hook in git to create that mirror. So, for example, the most critical aspect of your [[wiki]] is the <code>LocalSettings.php</code> configuration file. You don't want to commit the file to the version control of the project because it would expose sensitive data. etckeeper can be used to track changes to any file on the filesystem, but it's done discretely on the host. | ||
git repos in the directories you want to track can cause problems. One useful addition is to filter out anything found in '.gitignore' per the discussion at https://stackoverflow.com/questions/13713101/rsync-exclude-according-to-gitignore-hgignore-svnignore-like-filter-c Or, since this script is just using rsync, you can add your own special cases as rsync calls | |||
<code>vi /etc/etckeeper/commit.d/20mirror-outside-files</code> | <code>vi /etc/etckeeper/commit.d/20mirror-outside-files</code> | ||
< | <syntaxhighlight lang="bash"> | ||
#!/bin/sh | #!/bin/sh | ||
set -e | set -e | ||
| Line 30: | Line 48: | ||
echo " $LOCAL_PATH" | echo " $LOCAL_PATH" | ||
mkdir -p $MIRROR_ROOT/$LOCAL_PATH | mkdir -p $MIRROR_ROOT/$LOCAL_PATH | ||
rsync -a $LOCAL_PATH/ $MIRROR_ROOT/$LOCAL_PATH | rsync -a --filter=':- .gitignore' $LOCAL_PATH/ $MIRROR_ROOT/$LOCAL_PATH | ||
} | } | ||
| Line 40: | Line 58: | ||
rsync -a $LOCAL_PATH $MIRROR_ROOT/$DIRPATH | rsync -a $LOCAL_PATH $MIRROR_ROOT/$DIRPATH | ||
} | } | ||
# special case where we don't want to mirror a sub-directory | |||
# we could also add a dummy .gitignore to the 'bin' directory | |||
rsync -a --exclude=ansible/ /home/greg/bin/ $MIRROR_ROOT/home/greg/bin/ | |||
########################################### | ########################################### | ||
| Line 47: | Line 69: | ||
mirror_file "/var/www/html/wiki/LocalSettings.php" | mirror_file "/var/www/html/wiki/LocalSettings.php" | ||
mirror_dir "/home/greg/data" | mirror_dir "/home/greg/data" | ||
mirror_dir "/home/greg/bin" | ## Special case handled above | ||
</ | ## mirror_dir "/home/greg/bin" | ||
</syntaxhighlight> | |||
== Problems with Hard-linked files == | |||
I got this with a recent <code>yum install</code> | |||
<pre> | |||
etckeeper warning: hardlinked files could cause problems with git: | |||
./fail2ban/action.d/badips.pyc | |||
./fail2ban/action.d/badips.pyo | |||
./fail2ban/action.d/smtp.pyc | |||
./fail2ban/action.d/smtp.pyo | |||
</pre> | |||
I looked at the .gitignore in /etc and .pyo and .pyc files are already ignored, so there is no problem. In fact, you can verify that git is NOT tracking these files in etc with the following: | |||
<syntaxhighlight lang="bash"> | |||
git ls-files fail2ban | grep py | |||
</syntaxhighlight> | |||
and compare to actual directory contents <code>ls -al /etc/fail2ban</code> | |||
<syntaxhighlight lang="bash"> | |||
# What files am I intentionally ignoring with .gitignore? | |||
git ls-files --other --ignored --exclude-standard | |||
# same as | |||
git status --ignored | |||
</syntaxhighlight> | |||
[[Category:System Administration]] | [[Category:System Administration]] | ||
[[Category:Version Control]] | [[Category:Version Control]] | ||
[[Category:DevOps]] | [[Category:DevOps]] | ||
[[Category:VCS]] | [[Category:VCS]] | ||