Scenario:
Yesterday i decided to play with my conky configuration file. I edited it and then saved it. Today when i ran conky somehow i didn't like it. It wasn't looking as good as my old configuration. Now here comes the problem! I just can't seem to get the current config to look like the old one! I have forgotten what changes i made yesterday! Damn!Fortunately it was just a conky configuration file. what if it was some system file? I would have broken my system. What if it was some important work file? That would have been disaster!
This kind of disaster can happen to anybody and everybody who sometime or other edits their files. It happens to the best of us. A simple thing can prevent such a disaster from happening. You may ask what is that?
That simple thing is create a backup copy of file every time before opening it. But implementation of this practice is not easy! Stress, hurry or plain old silly moment and "Hell! I forgot to backup the damn thing!" Disaster!!!
Solution:
I have pieced together a bash script and named it 'hakbak'. hakbak automatically creates backup copy of a file you are about to open. hakbak adds the current time (d:m:y.h:m:s) at the end of file extension so if you have edited a file multiple times you will have multiple backups of that file to choose from. hakbak is almost bulletproof!
What is more intersting is that hakbak after creating backup will also open the file in your chosen application. What this means is that you can create one version of hakbak that can create backup and open a file in gedit or text editor of your choice. If you are a musician or a sound professional you can modify hakbak and make another version that can create backup of your audio file before opening it in for example in audacity. Similarly if you are an artist working with images you can create one more version of hakbak to create backup of your image file before you open it to edit in gimp. You can create as many versions of hakbak you want. Possibilities are endless!
How to install hakbak:
First download the 'hakbak.zip' file. Download Links are at the bottom of the page. Extract 'hakbak.zip' and copy the extracted folder 'hakbak' to your user directory.
We will in this example create three versions of hakbak. You can create as many as you please.
First version is for text and configuration files. We will call this version 'hakbaktext.sh'. Open terminal and run the following command
cp ~/hakbak/hakbak.sh ~/hakbak/hakbaktext.sh
Second version for audio files.
cp ~/hakbak/hakbak.sh ~/hakbak/hakbakaudio.sh
Third version for image files.
cp ~/hakbak/hakbak.sh ~/hakbak/hakbakimage.sh
Okay time to set default applications that hakbak will use.
By default hakbak will open text or configuration files in 'GNU nano'. If you like to edit files with 'GNU nano' skip this step. But if you prefer 'gedit' you can use it as the default application. Run the following command in terminal to make 'gedit' open text and configuration files via hakbak. If you use some other text editor like leafpad, mousepad, geany, vim etc. just replace 'gedit' in the following command with the name of the text editor of your choice.
sed -i 's/nano/gedit/' ~/hakbak/hakbaktext.sh
For second version i'm gonna set 'audacity' as default. Just as above run this command in terminal and again replace 'audacity' in this command with the audio editor of your choice.
sed -i 's/nano/audacity/' ~/hakbak/hakbakaudio.sh
And the third version for image files. Replace 'gimp' in the following command if you use a different image editor.
sed -i 's/nano/gimp/' ~/hakbak/hakbakimage.sh
Now we are going to move all these versions of hakbak to a suitable location. Open terminal and run the following commands.
sudo cp ~/hakbak/hakbaktext.sh /usr/bin
sudo cp ~/hakbak/hakbakaudio.sh /usr/bin
sudo cp ~/hakbak/hakbakimage.sh /usr/bin
Now we need to make them executable. In terminal run the following commands.
sudo chmod a+x /usr/bin/hakbaktext.sh
sudo chmod a+x /usr/bin/hakbakaudio.sh
sudo chmod a+x /usr/bin/hakbakimage.sh
How to use hakbak:
It's very simple. Whenever you want to open a file and if it's a text or configuration file just open terminal, type hakbaktext.sh and press 'Enter' key. hakbak will run and ask for the file path. Give your file path and hit 'Enter'. hakbak will create a backup of that file with current time at the end of the file extension and open it in 'gedit' or any other text editor you have set.
For example i want to open and edit .conkyrc file which is inside 'conky' folder in user directory. I will open terminal and run,
And when prompted for the complete file path i will enter my file path,
Easy, isn't it?
I can do the same with audio files. This time i will run hakbakaudio.sh in terminal,
For example i want to open and edit .conkyrc file which is inside 'conky' folder in user directory. I will open terminal and run,
hakbaktext.sh
And when prompted for the complete file path i will enter my file path,
~/conky/.conkyrc
Easy, isn't it?
I can do the same with audio files. This time i will run hakbakaudio.sh in terminal,
hakbakaudio.sh
And will enter the path to my audio file when prompted,
~/music/test.mp3
When i want to open an image for editing i will open terminal and run,
hakbakimage.sh
Then i will enter the path to the image i want to edit,
~/images/image1.jpg
When you want to edit text or config files that require super user privileges just use 'sudo' in terminal with hakbak.
For example i want to change the default boot entry of grub2. For this i need to open and edit '/etc/default/grub' file. Now i will need elevated privilege to edit this file. So i will run hakbaktext.sh with 'sudo' or 'su' in terminal,
sudo hakbaktext.sh
I will be prompted to enter 'sudo' password and after that when hakbaktext.sh asks for the complete file path i will enter the path to the default grub config file,
/etc/default/grub
Conclusion:
I'm not a programmer and this script might not be the most elegant one but it does the job! And it does it with simplicity! You don't have to install any thing extra. And you just run it from terminal so it fits in your routine easily. And once you start using hakbak you will almost never lose important data. You will always have multiple backups ready if something goes wrong. hakbak is like your personal 'Version control system'.
Comments, Suggestions, Thoughts are welcome! Cheers!!!
Update (26-06-13):
Bodhi Linux forum member spainach came up with hakbakmod. hakbakmod comes with install script, .desktop file and zenity. Install script makes it very easy to install and zenity gives graphical user interface and .desktop file makes it available from menu. So you don't have to use terminal to run and operate hakbak. Thanks spainach for this wonderful mod. You can download hakbakmod from the Download section below.
Download Links:
Download Link 1:
Download Link 2:
Download Link 3:
Download hakbak
Download Link 4
Download hakbakmod
Download Link 5
Download hakbakmod
Download Link 6
Download hakbakmod
Download Link 4
Download hakbakmod
Download Link 5
Download hakbakmod
Download Link 6
Download hakbakmod
No comments:
Post a Comment