Skip to content

prashantjoge/archlinux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

120 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Archlinux configuration files

Easy way to manage linux configs

Linux Config File Version Control and Backup on GitHub

A simple script that enables a powerful workflow: manage all configuration files on your Linux machines with Git and back them up on GitHub or any other version control host.

This is how it's used:

  • Create a private GitHub repository for each machine's backup.
  • Run the Script on a Linux machine. It copies all configuration files (and/or anything else you want to backup) to a local Git repository.
  • Push the changes from a machine's local repository to GitHub.

Preparation (Once per Machine You Want to Backup)

These preparation steps only need to be done once on each machine whose configuration you want to backup. [Check out how to perform a backup] (#performing-a-backup).

Local Backup Directory

Create a backup data directory, assign write permissions to the adm group and set the group ID so that all files created in the directory get the adm group:

sudo mkdir -p /backup/data  
sudo chown -R root:adm /backup/
sudo chmod -R 774 /backup/
sudo chmod -R g+s /backup

Clone the backup script from its public repository into the bin subdirectory and make it executable:

Git Configuration

If this is the first time you are using Git on this machine, configure your username and email:

git config --global user.name "your name"
git config --global user.email "email@domain.com"

Create a Git repository in the backup data directory:

cd /backup/data
git init

SSH Keypair

Create an SSH keypair to be used as GitHub deploy keys. We'll use the computername as key comment, leave the passphrase empty and move the generated keypair to the new repository. We also limit access to the owner or pushing to GitHub is blocked:

cd /backup/data    
ssh-keygen -t rsa -b 4096 -C "www1-ubuntu"    
mkdir /backup/data/.ssh    
mv ~/.ssh/id_* /backup/data/.ssh/    
chgrp adm .ssh/id_*    
chmod 600 .ssh/id_*

GitHub Repository

Create the private GitHub repository:

  • Create a new private repository for the current machine's configuration backup.

  • Add the public key file /backup/data/.ssh/id_rsa.pub as a deploy key to the new repository. Add the GitHub remote repository and push:    

    git remote add origin
    git@github.com:YOUR_ORGANIZATION/YOUR_REPOSITORY.git
    

    Configure What to Backup The script copies every file or directory\

    listed in the source file /backup/config/backup_src.txt. Globbing (including recursive wildcard expansion) is enabled.

The recommended default content for the backup source file is the following:

/etc/**/*.conf
/etc/ssh/sshd_config

Create the backup sources file:

mkdir /backup/config
nvim /backup/config/backup_src.txt
[paste the file content and save the file]

Set the SSH Key Per Repository

Normally, the SSH keys used by Git are configured once per user. In this case, however, we want to specify the keys per repository. Configure Git to use the new SSH key for this repository:

   git config core.sshCommand "ssh -i /backup/data/.ssh/id_rsa -F /dev/null"

Performing a Backup

Run the script:

cd /backup/data/
/backup/bin/copy_files.sh

Automate further using systemctl services or cron jobs

You can take this a step further by creating a custom service with a timer (to schedule it) or by use cron to schedule it. Note that Archlinux does not support crontab by default. Install crony to create a cron job.

Quick Git Rub Off

git clone url             # To create directory on local
git add .                 # Then add to staging
git commit -m "comments"  # Commit the files to local repo
git push origin master    # Commit to Github

Remove dir from GIT

git rm --cached -r diretory
Git add .
git commit -m 'comment'
git push origin master

About

a collection of my archlinux scripts

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors