Skip to content

Instantly share code, notes, and snippets.

@betandr
Last active August 29, 2015 14:23
Show Gist options
  • Save betandr/49c116ee9d10114eb0f3 to your computer and use it in GitHub Desktop.
Save betandr/49c116ee9d10114eb0f3 to your computer and use it in GitHub Desktop.

Although you may have great version control in place, sometimes stuff gets inadvertently overwritten or messed up…in this case it's always good to do a quick backup before you do anything potentially serious. I've written a little Bash shell hack which I thought might be useful:

In your ~/.bash_profile (or ~/.bashrc if you load that in your .bash_profile) file, add the line:

alias bag='b=$(basename `pwd`);cd ..;tar -cvf  $b"_"$(date +'%Y-%m-%d_%H-%M-%S')".tar.gz" "./"$b"/";cd $b'

...then re-load your bashrc by running 'source ~/.bash_profile' or 'source ~/.bashrc'.

When you're then in your working directory, simply run 'bag' which will create a time-stamped, gzipped tar file in the directory above the one you're in, containing the contents of the directory you're currently in. Such as:

foo_2015-06-16_15-38-59.tar.gz

@Qambar
Copy link

Qambar commented Jun 16, 2015

works quite well, but i would suggest adding a "cd $b" at the end so that we come back to the directory we left.

@betandr
Copy link
Author

betandr commented Jun 17, 2015

Nice spot, @Qambar, thanks! Added! :)

@Qambar
Copy link

Qambar commented Jun 17, 2015

perfect! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment