{"id":26,"date":"2015-09-28T07:21:22","date_gmt":"2015-09-28T01:51:22","guid":{"rendered":"http:\/\/madhurendra.com\/?p=26"},"modified":"2015-09-28T07:23:46","modified_gmt":"2015-09-28T01:53:46","slug":"backup-server-configurations-to-git","status":"publish","type":"post","link":"https:\/\/madhurendra.com\/backup-server-configurations-to-git\/","title":{"rendered":"Backup Server Configurations to Git"},"content":{"rendered":"

When you have multiple servers it pain to remember every configuration and it may take hours to configure servers again incase you need.
\nIt is also impractical to copy each files.<\/p>\n

There are few tools available but they come with overhead attached moreover its fun to write custom solutions \ud83d\ude42<\/p>\n

1. Create directory
\n2. cd into it.
\n3. Initialize git
\n4. Add a remote
\n5. Create branch specifically for that server
\n6. Check out branch
\n7. Add shell script
\n8. Make a commit and push to server.<\/p>\n

mkdir backup\r\ncd backup\/  \r\ngit init\r\ngit remote add git@tikaj.com:tikaj\/ConfigurationBackups.git\r\ngit branch $(hostname)\r\ngit checkout $(hostname)\r\n\r\n#This file contains space delimited configuration file name and path relative to git.\r\ntouch ConfigurationFiles.list\r\n\r\nvi backup.sh<\/pre>\n

Content of backup.sh<\/p>\n

#!\/bin\/bash\r\nBASEDIR=$(dirname $0)\r\n\r\ncd $BASEDIR\r\n\r\nwhile read line; do \r\n IFS=' ' read -a A <<< \"$line\"\r\n cp ${A[0]} $BASEDIR\/${A[1]} \r\ndone < ConfigurationFiles.list\r\n\r\n\r\n#Add new files and commit changes\r\ngit add --all :\/\r\ngit commit -m \"Update configuration files.\"\r\ngit push origin  $(hostname)\r\n <\/pre>\n

Then, Don't forget to generate SSH key adding key to your git server. <\/em> <\/p>\n

\r\ngit push -u origin  $(hostname)\r\n<\/pre>\n

Now i can either setup a cron job or add command to daily backup script to update configuration files.
\nusing <\/p>\n

ssh mad@tikaj.com \"bash \/root\/backup\/backup.sh\"<\/pre>\n

from remote.<\/p>\n","protected":false},"excerpt":{"rendered":"

When you have multiple servers it pain to remember every configuration and it may take hours to configure servers again incase you need. It is also impractical to copy each files. There are few tools available but they come with overhead attached moreover its fun to write custom solutions \ud83d\ude42 1. Create directory 2. cd … <\/p>\n

Continue reading<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[2,3,6,8],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pciGs2-q","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/posts\/26"}],"collection":[{"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/comments?post=26"}],"version-history":[{"count":5,"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/posts\/26\/revisions"}],"predecessor-version":[{"id":31,"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/posts\/26\/revisions\/31"}],"wp:attachment":[{"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/media?parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/categories?post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/tags?post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}