Putting date into folder name at creation.

On the subject of backups (non-server)...

  • I make incrimental backups every day (weekly cycle).

    Votes: 1 6.3%
  • I make replacement backups once every week.

    Votes: 2 12.5%
  • I make a replacement backup once a month.

    Votes: 6 37.5%
  • I'm so good I don't need backups :) (i.e., famous last words)

    Votes: 7 43.8%

  • Total voters
    16
  • Poll closed .

Gwailo

B.A. Economics (Hon)
My case: I have a firewire external disk, which is noisy (fan) that I use for backup. I don't want to leave it on 24/7 and use a cronjob to copy stuff because i can't leave it on all the time.

What I'd ideally like to do is make a terminal command alias that does something like this:

<CODE>
mkdir /volumes/firedisk/backup/[INSERT CURRENT DATE]
cp -r ~/* /volumes/firedisk/backup/[CURRENT DATE]/
cp -r /library/webserver/* /volumes/firedisk/backup/[CURRENT DATE]
</CODE>

Is it possible to bind a command like that, or do i need to use a PERL script; BTW I don't know jack all about PERL. So far i haven't come across an instance in Linux where you can insert nested functions at the command line, just consecutive (with the pipe, like ls | grep blah).

Thanks a bunch!
 
The reason for this is that i'd like to leave my FW on during the day and remotely issue a backup command.

For this, it would be nice if I could run the cp process as a background thread, so if my connection fails for whatever reason the copy continues, and it doesn't hijack my interface in the x minutes it takes to copy the 10GB...

Another thing comes to mind. If I ran this as a background process, would I be able to alert the user with some kind of message or terminal bell once the copy had completed?

(This is starting to look more and more like a PERL application, or maybe AppleScript...)
 
For this, Perl can be mind-bogglingly simple.

For each system command you want to run, enclose it in quotes and put 'system' before it. So your tasks would look like:
Code:
#!/usr/bin/perl

system "mkdir /volumes/firedisk/backup/[INSERT CURRENT DATE]";
system "cp -r ~/* /volumes/firedisk/backup/[CURRENT DATE]/";
system "cp -r /library/webserver/* /volumes/firedisk/backup/[CURRENT DATE]";
To insert the current date it gets a little trickier. But this should get you started. I'll hack around and find a good way to do this and post once it's finished.
 
Here's the full script:
Code:
#!/usr/bin/perl

use strict;

my $date = scalar localtime();
$date =~ s/ /_/g; # Replace space with underscore

system "mkdir /volumes/firedisk/backup/$date";
system "cp -r ~/* /volumes/firedisk/backup/$date/";
system "cp -r /library/webserver/* /volumes/firedisk/backup/$date";
The date format then becomes something like "Tue_Apr_23_16:08:30_2002".

Save this to a file (most people use a .pl extension, but it's not necessary), then issue chmod +x filename to make it executable.

To run it, simply type in the filename.
 
Oh, sure, testuser. Try to one-up my Perl script with your shell script. I know how it goes... ;)

I included the time and day and all that stuff to make for more unique folder/file names. And because I knew I didn't have a lot of time to format it all nice and pretty because I knew your shell script was on its way... :D
 
If you want something which sorts nicely (alphabetically), replace testuser's definition of dirName with
Code:
dirName=`date '+%Y%m%d'`
which will give you a string in the format of YYYYMMDD, so sorting by date via the name is easy.
 
tar cf - sourcedir | ( cd $backupdir; tar xf - )

This will not be faster on big files, but on small files it will tend to read a bunch and write a bunch which is usually somewhat more efficient. Also, it will pick up symlinks as symlinks, rather than copies; gnutar will try to do the right thing with hard links. Both will fail on extended flags and resource forks.
hfspax in tar mode might help in this respect.

Run as root.
 
A big THANK YOU to all who replied, and so completely too!

As soon as I initiated a copy in the finder, hopefully for the last time, my power cut out and I lost *everyting* on my fire disk (corrupted btree).

Dang*** shame too, was about to cry. But at least now I can back things up to it hah. well after the format.
 
Back
Top