Creating a Backup Script in Bash Terminal
Hey guys, long time reader first time poster.
I play around with Unix a bit, mostly for fun. I'm doing a few online tutorials to further my knowledge and have run into a problem i just cant get my head around. Am hoping you guys can help! So the problem is as follows: You have to create a script that when run will copy all files in your current working directory and put them in a backup folder. Now the catch is those files are filtered by an input from the user which related to when the file was last modified. Something like: backup.sh -m 02 -y 2011 will backup all files that were modified after the feb, 2011 hope that makes sense. If you've any questions please ask. I'm racking my brain and just cant work out how to go about this. Damn frustrating |
The key cmd there is 'find' http://linux.die.net/man/1/find, which has many options to select files by date eg 'mtime'
Here's some good bash links http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ |
Thanks heaps for your reply.
I figured id be relying on that command for this. I had something like Find * mtime -3 | cp /backup I understood that as find all files that were modified in the last 3 days and copy those to the /backup directory Now i was getting errors with that first of all Second im stuck really on going that extra step to make mtime an input by the user. Also if im able to use months and years in the mtime filter too Sorry thinking out loud here. Some of these answers are possibly in those links and i will check them out thanks again |
Just a few hints
Code:
find /path -mtime -3 ... You must specify the path for find to start at and it can't be wildcard like '*' |
thanks for that once again.
i think the find command is what was throwing me. haven't used it a whole lot. Adding a path seemed to help but im still stuck on parsing variables into it to change the files to find based on a given modify date. sudo example, find /home mtime -(march 2012)... |
Well, the usual arrangement for a backup system is to do a rolling backup of eg all files lees than x days old, hence the section I referred you to.
That way, no files get missed out. If you want the user to be able to specify a particular date or date range, you're going to have to read up on the date cmd http://linux.die.net/man/1/date and read those links above to figure how to do date calcs, then convert to n days ago to be able to use find to grab them. I guess it would be a good little programming project; its do-able but sufficiently non-trivial to be interesting and a good learning experience. |
Well that's why im taking it on and trying to learn a bit more.
Also why im here trying to get help. Thanks for your comments chris |
probably you can try rsync also...
|
All times are GMT -5. The time now is 03:47 AM. |