While I was up really late the other night I had just gone about automating deploying some of my blog. I was tired at that point and had just made a few mistakes copying files around from the dev site to the live site. So instead of just realizing that I'm tired and really should just be sleeping I decide that instead of this error prone manual copying of files I should automating the process. Part of this involved clearing out the old folder that contained the processed files then copying over the new files. Given that Pelican already has a makefile I decided to create a makefile target that "built" the live site. (Using the Fabric file would most likely have been a better choice, I'm trying to move away from makefiles these days wherever better tools exist)
So I added this makefile directive to automate the directory copy step:
live_folder: rm -r * ~/pelican_live/ cp -r $(OUTPUTDIR)/* ~/pelican_live/
So I committed my changes to git and pushed those to the GitHub repository. A bit later I then ran the makefile and refreshed the web page. The page was gone. So I go to check the files in the directory they were all gone too!
Luckily this command doesn't delete the .git folder so recovery was particularly easy, I just ran git checkout for all the files. Because I had all the files in version control I didn't lose anything. Had the .git folder been deleted I would have had to first get the repository off GitHub which, while slightly more annoying, would have been very manageable. 
At this point I immediately changed the offending makefile line.
live_folder: cd ~/pelican_live/ && rm -r ./* cp -r $(OUTPUTDIR)/* ~/pelican_live/
This was one of those moments where I was so glad I went to the effort to properly set things up with version control. The site was back up and running again within 15 minutes. If I didn't have version control I might have lost the entire site right there and then. I think this is a really good example of the value of correctly using version control software.
|||I back up the git repository by pushing it elsewhere quite frequently to avoid data loss disasters like the one that almost happened here.|