LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-27-2007, 11:14 PM   #1
HunterColt22
LQ Newbie
 
Registered: May 2007
Posts: 4

Rep: Reputation: 0
Using Awk to make Archives based on dates.


Just as the title says, I wish to know how to make a script program that when run will make back ups of my files and directories on my system, while catgaorizing them dependt upon the year and month they were first made in. I know this is an odd question to ask for my first post, but this is really bugging me, any help would be great. Also, hi I am sort of new to Linux, have been working with it for a little bit, but not to too long. What I have been working with I like but I am not an ace programmer so its a learning curve just a bit for me. Again any help would be great and thanks again everyone.

~HunterColt22
 
Old 05-28-2007, 01:09 AM   #2
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,440

Rep: Reputation: 52
This is a very simple bash script to backup a directory called "twantrd":
Code:
#!/bin/bash

date=`date '+%Y%m%d'`
tar -zcf twantrd.tar.gz.${date} twantrd
tar is pretty much the most commonly used command to make backups of files/directories. I added in the date command so that you know when that archive has been created and you can sort it however you like. If you don't know what the flags I used mean, a simple 'man <command>' will tell you. Let us know if you need additional help understanding this script or expanding it even more.

-twantrd
 
Old 05-28-2007, 09:03 AM   #3
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
How do you want to do the categorizing: back up directory structure, a text file listing, something else?
 
Old 05-28-2007, 04:43 PM   #4
HunterColt22
LQ Newbie
 
Registered: May 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Basically, I want to be able to back up my all of my files on my current home directory, but when it backs them up, I would like the script to put the backups into different directories. I just need to know how to make the tar command back up my home directory contents, and then incorporate the date function into it. I was thinking it would be something like

#!/bin/bash

tar -zcf#Insert command to back up home directory here#.tar.gz

if [# Any file made in may of 2006 is found]
then
#Put it in a directory called may 06

and have that same setup for each month, if I can do this would it just be a bunch of if elif statements? Or would it be something completly different? thanks agian for all the help you are all giving.

Last edited by HunterColt22; 05-28-2007 at 09:03 PM.
 
Old 05-29-2007, 02:50 AM   #5
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,440

Rep: Reputation: 52
From the top of my head, a for loop is what you are looking for. Something like:

Code:
for month in "Jan" "Feb" "Mar" ....
do
# ls files and look to see if their modification time stamp matches the month
# if they do, copy them to their appropriate directory (if statement goes here)
done

# Now run your tar command to backup each directory.
Start writing some code and we'll help you with your logic and any questions you may have.

-twantrd
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Make your own packages for Debian-based systems LXer Syndicated Linux News 0 02-23-2007 03:31 AM
xCopying from NTFS XP to Linux Based storage - problem = dates discrimination amfony Linux - General 4 11-30-2006 04:02 PM
Make aweb based tool to adminstrate Unix systems adam_blackice Programming 4 11-28-2006 03:53 AM
How to make Debian based distribution? chrisstooss Debian 6 05-24-2005 12:11 PM
Can ANYONE explain how to make 6 chanell NForse 2 based sound work? buboleck Linux - Hardware 0 01-30-2004 02:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration