### etckeeper Configuration File Example Source: https://context7.com/pkroma/etckeeper/llms.txt Example configuration for /etc/etckeeper/etckeeper.conf, controlling VCS selection, commit options, package manager integration, and auto-push behavior. This file dictates how etckeeper operates. ```bash # /etc/etckeeper/etckeeper.conf # The VCS to use (git, hg, bzr, or darcs) VCS="git" # Options passed to git commit when run by etckeeper GIT_COMMIT_OPTIONS="" # Abort package install if uncommitted changes exist #AVOID_COMMIT_BEFORE_INSTALL=1 # Disable daily autocommits via cron #AVOID_DAILY_AUTOCOMMITS=1 # Suppress warnings about special files (pipes, sockets, etc.) #AVOID_SPECIAL_FILE_WARNING=1 # Package manager configuration HIGHLEVEL_PACKAGE_MANAGER=apt LOWLEVEL_PACKAGE_MANAGER=dpkg # Auto-push to remote after each commit PUSH_REMOTE="" # For multiple remotes: PUSH_REMOTE="origin backup gitlab" ``` -------------------------------- ### Initialize etckeeper Repository Source: https://context7.com/pkroma/etckeeper/llms.txt Initializes a version control repository in /etc, sets up VCS, creates ignore files, configures pre-commit hooks for metadata tracking, and stages files for the initial commit. This is typically done automatically during package installation. ```bash # Install etckeeper (Debian/Ubuntu) apt-get install etckeeper # Initialize the repository (usually done automatically during package install) etckeeper init # Verify initialization cd /etc git status # Make the initial commit git commit -m "initial checkin" # Optimize storage git gc ``` -------------------------------- ### etckeeper Post-Install Hook Source: https://context7.com/pkroma/etckeeper/llms.txt Automatically called after package installation. It commits changes made by the package manager, including a summary of package operations (installed, upgraded, removed). This ensures that changes made by package management are tracked. ```bash # This is called automatically via apt hooks # Manual invocation after dpkg operations: dpkg -i some-package.deb etckeeper post-install # Example auto-generated commit message: # committing changes in /etc after apt run # # Package changes: # -nginx 1.18.0-1 # +nginx 1.20.0-1 # +nginx-common 1.20.0-1 ``` -------------------------------- ### etckeeper Pre-Install Hook Source: https://context7.com/pkroma/etckeeper/llms.txt Automatically called before package installation. Its primary function is to commit any uncommitted changes in /etc to prevent data loss during upgrades. This is typically handled by system hooks (e.g., apt hooks). ```bash # This is called automatically via apt hooks # Manual invocation (rarely needed): etckeeper pre-install # The apt hook configuration (/etc/apt/apt.conf.d/05etckeeper): # DPkg::Pre-Invoke { "if [ -x /usr/bin/etckeeper ]; then etckeeper pre-install; fi"; }; # DPkg::Post-Invoke { "if [ -x /usr/bin/etckeeper ]; then etckeeper post-install; fi"; }; # To require manual commits before installs, set in etckeeper.conf: # AVOID_COMMIT_BEFORE_INSTALL=1 # This will abort apt/yum if uncommitted changes exist ``` -------------------------------- ### etckeeper Multi-Machine Comparison Source: https://context7.com/pkroma/etckeeper/llms.txt Compares /etc configurations across multiple machines using git remotes. This involves adding another machine's /etc as a remote, fetching its data, and then using `git diff` to compare configurations or `git log` to view its history. Specific configurations can be cherry-picked. ```bash # On machine "darkstar", add another machine's /etc as a remote cd /etc git remote add dodo ssh://dodo/etc git fetch dodo # Compare configurations git diff dodo/master group git diff dodo/master passwd git diff dodo/master -- nginx/ # View the other machine's history git log dodo/master --oneline # Cherry-pick specific configurations git checkout dodo/master -- nginx/sites-available/mysite.conf etckeeper init # Restore correct permissions etckeeper commit "imported nginx config from dodo" ``` -------------------------------- ### etckeeper -d Directory Operation Source: https://context7.com/pkroma/etckeeper/llms.txt Operates on a clone of the /etc repository in a different directory. This is useful for testing changes before applying them to the live system. It allows cloning, initializing etckeeper in a staging directory, making changes, committing them, and comparing with the live /etc. ```bash # Clone /etc to a staging directory (secure method) mkdir /my/staging cd /my/staging chmod 700 . git clone /etc cd etc etckeeper init -d . chmod 755 .. # Make changes in staging vim passwd etckeeper commit -d . "test user changes" # Compare with live /etc git diff /etc/master # Create a bare backup repository ssh server 'mkdir /etc-backup; cd /etc-backup; chmod 700 .; git init --bare' cd /etc git remote add backup ssh://server/etc-backup git push backup --all ``` -------------------------------- ### etckeeper uninit Command Source: https://context7.com/pkroma/etckeeper/llms.txt Removes all VCS and etckeeper data from /etc. This operation destroys version history and should be used with caution. It can be forced without an interactive prompt using the -f flag. It's commonly used when switching VCS. ```bash # Remove etckeeper and VCS data (interactive prompt) etckeeper uninit # Force removal without prompt etckeeper uninit -f # Common use case: switching VCS etckeeper uninit -f vim /etc/etckeeper/etckeeper.conf # Change VCS="git" to VCS="hg" etckeeper init # Note: uninit preserves custom patterns in ignore files # that are outside the "managed by etckeeper" block ``` -------------------------------- ### etckeeper Remote Backup Configuration Source: https://context7.com/pkroma/etckeeper/llms.txt Configures automatic pushing to remote repositories after each commit. This involves setting up a remote repository using `git remote add` and configuring `etckeeper.conf` with the PUSH_REMOTE variable. Multiple remotes can be specified. ```bash # Set up remote repository cd /etc git remote add origin ssh://backupserver/etc-repo.git # Configure etckeeper.conf to auto-push # PUSH_REMOTE="origin" # For multiple remotes: git remote add gitlab ssh://gitlab.example.com/admin/etc-backup.git git remote add github ssh://github.com/myorg/server-etc.git # PUSH_REMOTE="origin gitlab github" # Each commit will now automatically push to all remotes etckeeper commit "configuration change" # Pushes to origin, gitlab, and github ``` -------------------------------- ### Execute VCS Commands with etckeeper Source: https://context7.com/pkroma/etckeeper/llms.txt Runs arbitrary Version Control System (VCS) subcommands within the etckeeper environment, ensuring proper environment variables are set. This allows direct interaction with the underlying VCS (e.g., Git, Mercurial). ```bash # View differences etckeeper vcs diff # View commit history etckeeper vcs log --oneline -10 # Show status etckeeper vcs status # Add a remote for backups etckeeper vcs remote add backup ssh://backupserver/etc-backup # Push to remote etckeeper vcs push backup master ``` -------------------------------- ### etckeeper pre-commit Hook Source: https://context7.com/pkroma/etckeeper/llms.txt Stores file metadata (permissions, ownership, empty directories) in the .etckeeper file. This is typically called automatically as a VCS pre-commit hook but can be run manually. The .etckeeper file contains commands to restore metadata. ```bash # Usually called automatically, but can be run manually etckeeper pre-commit # The .etckeeper file contains commands like: # maybe chown root './shadow' # maybe chgrp shadow './shadow' # maybe chmod 0640 './shadow' # mkdir -p './empty-dir' # To restore metadata after checkout: cd /etc etckeeper init # This runs the .etckeeper script to fix permissions ``` -------------------------------- ### etckeeper update-ignore Command Source: https://context7.com/pkroma/etckeeper/llms.txt Updates the VCS ignore file with etckeeper's managed section. Custom ignore patterns outside the managed block are preserved. The -a flag forces the addition of the managed section if it's not present. ```bash # Update ignore file (only touches "managed by etckeeper" section) etckeeper update-ignore # Force add managed section if not present etckeeper update-ignore -a # Custom ignores can be added outside the managed block: # /etc/.gitignore example: # my-custom-ignore-pattern # # # begin section managed by etckeeper # # ... auto-generated patterns ... # # end section managed by etckeeper # # another-custom-pattern ``` -------------------------------- ### Commit Changes with etckeeper Source: https://context7.com/pkroma/etckeeper/llms.txt Commits all changes in /etc to the repository, automatically recording the username of the user who invoked the command via sudo/su. Supports commit messages via arguments or stdin. ```bash # Commit with a message etckeeper commit "updated nginx configuration" # Commit with message via stdin (useful for scripts) echo "automated configuration update" | etckeeper commit --stdin # After manual changes, review and commit cd /etc git status git diff etckeeper commit "modified ssh settings for security hardening" # The commit author is automatically set based on SUDO_USER # Example commit shows: Author: jsmith ``` -------------------------------- ### etckeeper Daily Auto-Commit Source: https://context7.com/pkroma/etckeeper/llms.txt A cron job automatically runs daily to commit any uncommitted changes in /etc. This behavior can be disabled by setting AVOID_DAILY_AUTOCOMMITS=1 in etckeeper.conf. The manual equivalent checks if the repository is unclean and then commits. ```bash # /etc/cron.daily/etckeeper runs automatically # Disable via etckeeper.conf: # AVOID_DAILY_AUTOCOMMITS=1 # Manual equivalent of what the cron job does: if etckeeper unclean; then etckeeper commit "daily autocommit" fi # The cron job also handles stale lock files from interrupted installs ``` -------------------------------- ### Check for Uncommitted Changes with etckeeper Source: https://context7.com/pkroma/etckeeper/llms.txt Checks if the /etc directory contains uncommitted changes. Returns exit code 0 if changes exist, non-zero otherwise. Useful for scripting to ensure a clean state before operations or to trigger commits. ```bash # Check for uncommitted changes if etckeeper unclean; echo "There are uncommitted changes in /etc" etckeeper commit "saving uncommitted changes" else echo "/etc is clean" fi # Use in scripts to ensure clean state before operations etckeeper unclean || { echo "No changes to commit"; exit 0; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.