0

I have Ubuntu Server 16.04.3 and daily I am making some changes to configuration files in /etc.

I want to synchronize these files daily and take a backup of them stored on another partition? How can I achieve this?

Zanna
  • 70,465
Nijo NV
  • 13

1 Answers1

0

Probably it is an overkill solution but you can use etckeeper, and similar question is well answered here.

In short:

  1. sudo apt install etckeeper
  2. Choose any git private repository (bitbucket if you want easy way, or your local git repo/folder on your own server)
  3. Add the repository as origin to the etckeeper cd /etc; git remote add origin <some-git-repo>
  4. Uncomment/add "PUSH_REMOTE="origin" in /etc/etckeeper/etckeeper.conf
  5. Make the initial commit cd /etc; git push -u origin master

And you are done. etckeeper has daily cronjob (/etc/cron.daily/etckeeper) that will do the trick as also a trigger (cat /etc/apt/apt.conf.d/05etckeeper) to apt-commands(apt-get, apt, aptitude) which will update on each package change. You can also invoke the commit manually by running etckeeper commit


If you want simpler solution - add a daily cron job:

cat >/etc/cron.daily/my_backup <<'EOF'
tar czf /your/backup/dir "etc_$(date +%F_%T|sed -e 's/:/-/g')" /etc
EOF

I personally suggest you not to backup on another partition on the same physical unless this is really separate SSD/HDD bought at different time/manufacturer from the one containing your /etc/ folder.

The best backup is somewhere apart form your main source of valuable information... Think of a simple fire scenarios for example.