Backup of files in the directory.
I was working on some scripts and the changes that I was making in the scripts was very dynamic, which I did want to keep backing up in the version control system. But for the peace of my mind, I wanted to keep a copy of the scripts, whenever it was in working state.
Since I had multiple files, so it would make more sense to have a script that could copy all the files in the current directory to “old” directory without over-writing the existing files. So, I wrote a script that would postfix the files with a number. With this approach, finally what I had was the following:
#!/bin/bash - #=============================================================================== # # FILE: backup.sh # # USAGE: ./backup.sh # # DESCRIPTION: Backup all the current files. # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Amit Agarwal (aka), amit.agarwal@roamware.com # COMPANY: # CREATED: 08/19/2011 02:43:32 PM IST # REVISION: --- #=============================================================================== count=$(cat old/count) if [[ ! -f old/count ]] then count=$(ls -1 old |sed 's/.*\.//'|grep -vi "[a-z]"|sort|tail -1) fi ((count++)) echo $count >old/count [[ ! -d old ]] && mkdir old for i in * do [[ -f $i ]] && cp $i old/${i%%.*}.$count done echo "Backed up to $count"
Related articles
- Backup Exec 2010 R3: Backups and catalogs contain no files, only directories. (edugeek.net)
- Adding border to images. (amit-agarwal.co.in)
- Emacs Reboot #5 (avdi.org)
Related Articles:
- 2011/10/05 Get yourself some conkyrc files.
- 2010/03/16 Linux find command – Find file and directories faster and easier
- 2011/11/28 Linux hardware details.
- 2011/10/12 Cont: Get yourself some more conkyrc files.
- 2011/09/27 some interesting alias
Authored By Amit Agarwal
Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.