I just reinstalled my OS X recently, which not only enabled me to re-experience the joy of owning a new Mac, but also fixed problems like waking up into a partially slumber stage with a black screen and a movable cursor that is practically useless. Since I was going to
brew cask install a brand new Sublime Text Editor, I decided to spend a bit more effort customizing it. After some googling and experimentation, these are my settings:
This looked like a great environment to code in (I enabled vintage mode too so there are vim magic in it ;3 ) until I learnt that sometimes the text editor would revert some file back to its state x hours ago with no reason at all.
It is a nightmare. (Imagine happily committing your code only to learn all that you’ve written & tested no longer exist in the current dimensions in space-time.)
I still don’t have a clue what is the cause. (I only have a few plug-ins installed. I don’t think the plug-ins have to do with it.) But it has happened quite a few times and I have had my losses. Until I figure out what’s causing the strange phenomenon and get it fixed, I need to start taking precaution.
Here is a simple system that uses
watch with the help of
git to make backup of every single file in a directory every 90 seconds:
watchcan execute a line of code periodically in the terminal. The nice thing is that you can watch the outputs as it does.
Let’s say this is the directory containing projects you want to back up
1) Make a directory to keep the back up files
2) Make it into a git repo.
3) Write a bash script that
- Copy everything in the directory to the backup directory
- Remove all the
.gitfolders from each project in the backup directory (The
.gitfolder is what that determines a directory to be a git repo: removing it would turn git repo back to a normal directory. In order for
committo work, it is necessary to have every subdirectory as a non git repo. If not, the subdirectories containing
.gitwill be treated as git submodules.)
[Changes made in a git submodule can’t be committed as changes of the main git repo.]
- Git add & commit everything in the backup directory
and save it as
script.sh.(You can save it at anywhere you want)
Here is my
4) Simply run this script periodically using
watch (You can install it with brew if you don’t have it).
That’s it. Now every 90 seconds, the changes you made in your project (e.g.
/Users/a/_/0a-.github.com) would be recorded in the backup directory. You can view changes of the file using
The backup directory is going to take more and more disk space as time passes (as long as you remember to
watch -n 90 'bash script.sh' before you start to code each time). When you want to clean everything up, simply remove everything (including the
.git folder) and do a
git init again.
The great thing about using git is that only the changes of the files would be saved. So rather than having 10 backup copies of a project that are slightly different from one another, you’d only have one copy of it, and 9 indications of the different changes you made at different times.