LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 06-15-2012, 07:51 AM   #1
paperghost
LQ Newbie
 
Registered: Jun 2012
Posts: 2

Rep: Reputation: Disabled
Solaris 11


So i have been asked to write a script for a friend who has a server running solaris 11. My problem is the correct syntax i can't seem to get it work with the follow code, i have read through the date man page and found no work around
Code:
#!/bin/sh
rsync -avz /mnt/backups/`date --date=yesterday +\%Y-\%m-\%d`-`date --date=yesterday +\%A`/server1/ /mnt/backups/`date +\%Y-\%m-\%d`-`date +\%A`/server1/

This is the script i wrote to cleanup each day
Code:
#!/bin/sh
# Definitions
sixdaysago=$(date --date='5 days ago' +%Y-%m-%d-%A)
# Delete backups from 5 days ago
rm -rf /mnt/backups/$sixdaysago

Any one able to help me or a should i take a different approach in how i cycle through my backups ?

Last edited by paperghost; 06-15-2012 at 11:00 AM. Reason: fixed error in code
 
Old 06-15-2012, 08:23 AM   #2
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 509

Rep: Reputation: 203Reputation: 203Reputation: 203
Hi there,

I haven't come accross support for the --date option on any platform other than Linux.

As a possible solution I can offer a small hack of a perl script I used for this once.
Code:
#!/usr/bin/env perl
use strict;
my @days = qw/Sunday Monday Tuesday Wednesday Thursday Friday Saturday/;
my $utime = time();

if ($#ARGV == 0) {
        my $days_to_add = $ARGV[0];
        $utime += 86400 * $days_to_add;
}

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($utime);
$year += 1900;
$mon++;
$yday++;
printf "%04d-%02d-%02d-%s\n",$year,$mon,$mday,$days[$wday];
exit(0);
Save this to a file, make it executable, and run it with an optional number_of_days_to_add_or_subtract argument.

I hope this helps!
 
Old 06-15-2012, 10:07 AM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
This should just work on Solaris 11:

Code:
sixdaysago=$(/usr/gnu/bin/date --date='5 days ago' +%Y-%m-%d-%A)
 
1 members found this post helpful.
Old 06-15-2012, 11:00 AM   #4
paperghost
LQ Newbie
 
Registered: Jun 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jlliagre View Post
This should just work on Solaris 11:

Code:
sixdaysago=$(/usr/gnu/bin/date --date='5 days ago' +%Y-%m-%d-%A)
Thanks for that will test the code tomorrow, The main problem is the code to reduce the network transfer by syncing yesterdays files first then syncing only those that have been updated. Any idea how i could adjust the follow to work as currently i get the illegal operator error for the "--date=yesterday"
Code:
`date --date=yesterday +\%Y-\%m-\%d`-`date --date=yesterday +\%A`
Code:
rsync -avz /mnt/backups/`date --date=yesterday +\%Y-\%m-\%d`-`date --date=yesterday +\%A`/server1/ /mnt/backups/`date +\%Y-\%m-\%d`-`date +\%A`/server1/
 
Old 06-17-2012, 06:59 PM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by paperghost View Post
Any idea how i could adjust the follow to work as currently i get the illegal operator error for the "--date=yesterday"
Code:
`date --date=yesterday +\%Y-\%m-\%d`-`date --date=yesterday +\%A`
That would be:
Code:
$(/usr/gnu/bin/date --date=yesterday +\%Y-\%m-\%d)-$(/usr/gnu/bin/date --date=yesterday +\%A)
 
  


Reply



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
Choosing between Solaris 10 and Solaris Express to run sun xVM hypervisor crisostomo_enrico Solaris / OpenSolaris 1 09-26-2008 01:39 PM
LXer: Cool distro of the day: Damn Small Solaris (yes, I said Solaris) LXer Syndicated Linux News 0 02-26-2008 01:20 AM
LXer: Hp Puts Solaris on More X64 Servers, Partners for Solaris Emulation LXer Syndicated Linux News 0 02-07-2007 07:21 AM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 04:04 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