First of all, Happy New Year to each and everyone of you. I wish you success, good health and great sex in 2016.
Now with that out of the way, I wanted to write a script to backup all the directories in my web root on my Ubuntu 14.04 server because I accidentally sudo rm -rf /var/www/*
but stopped the process before too much damage was done.
After doing a lot of Google-ing I came across a very simple script that would work for me with some editing, of course: for i in */; do zip -r "${i%/}.zip" "$i"; done
I put the above code into a .sh file and ran it via my terminal and all directories were zipped separately which is just what I wanted.
I am quite sure that I got this code on http://stackoverflow.com but I maybe wrong. Regardless, I did not write it myself and therefore no credit should be given to me for this script.
I then ran a cron job to zip the directories periodically and to backup my databases as well (see Exporting All Databases Into Separate Files in Ubuntu 14.04 for the script I used). I am now safe from accidentally sudo rm -rf /var/www/*
my files as I now have them backed up every so often. Oh, and the backups are moved to a separate server (very important).