![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Convert String to Date | ORatjeuh | Shell Programming and Scripting | 2 | 05-06-2008 03:49 AM |
| Sorting Files by date and moving files in date order | rebel64 | Shell Programming and Scripting | 2 | 03-11-2008 08:45 AM |
| Date parsing into string, help! | martyb555 | Shell Programming and Scripting | 5 | 02-17-2008 06:12 PM |
| Extracting a string from one file and searching the same string in other files | mohancrr | Shell Programming and Scripting | 1 | 09-19-2007 12:17 AM |
| Backup Date & Time | EbeyeJJ | UNIX for Dummies Questions & Answers | 1 | 09-06-2005 07:14 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Guys,
I've got a quick logic question. I'm pretty savvy when it comes to shell scripting, however, I'm at a loss when it comes to writing a simple shell script to backup only certain files out of the month. I have a directory, for example, /data/backups/websites/domain. In each "domain" directory, there are files that are named by the date of when they were created, for example: Code:
deckerd-2008-04-11.tar.gz deckerd-2008-04-12.tar.gz deckerd-2008-04-13.tar.gz deckerd-2008-04-14.tar.gz deckerd-2008-04-15.tar.gz deckerd-2008-04-16.tar.gz deckerd-2008-04-17.tar.gz deckerd-2008-04-18.tar.gz deckerd-2008-04-19.tar.gz deckerd-2008-04-20.tar.gz All I'm wanting to do is backup one file per week, and create a monthly backup (about 4 backups per month). Maybe I should change the string creation to a "day" and just backup "sun" (sunday) for that current month and then backup the backups - that might work. However, I am wanting to run a backup everyday, then at the end of the month, backup the 4 (sometimes just 3) backups of that month and create a monthly backup. The reason being that if I need a daily backup during the month I have it, but after that month is over, I should (maybe) only need a weekly backup. This is how I want my system to be, and just needed some insight on how to actually get the individual (3 or 4 backups per month) to work. I already have it down how to create the backups and such, but taking what is currently being backed up (30 or 31 backups), and then at the end of the month, do the weekly backups (the part I'm wanting help with). If anyone has any code snippets or just a few lines of "this could work" or "try this", I'd be very grateful. Thanks in advanced, Drew |
| Forum Sponsor | ||
|
|
|
|||
|
start with this:
Code:
#!/bin/ksh
# print day of week
dow()
{
perl -e '
use POSIX qw(strftime);
$fmt = "%A"; # %a = abbreviated weekday %u = weekday number
$mday = substr("$ARGV[0]", 8, 2);
$mon = substr("$ARGV[0]", 5 ,2);
$year = substr("$ARGV[0]", 0 ,4);
$weekday =
strftime($fmt, 0, 0, 0, $mday , $mon - 1, $year - 1900, -1, -1, -1);
print "$weekday";
' "$1"
}
for file in $( ls *.tar.gz )
do
dt=$( echo $file | awk -F'-' { printf("%s-%s-%s", $2, $3, $4)}' )
day=$( dow $dt )
if [[ $day = "Sun" ]] ; then
# do backup here
fi
done
|