Jump to content
Server Maintenance This Week. ×

Newbie to Mac stuff


This topic is 5016 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hi,

We just installed a new mac mini server which will be used to host our FM files.

The files were before on a Windows server with FMS11. There was a VBScript that copied the backup files which were local to a remote folder.

Is there way I can use the same script? or I need to redo the script with AppleScript?

I really don't know anything about AppleScript. Is there a more developer friendly language, i.e. a standard scripting language (VB, JavaScript, C, ...)

Thanks

Link to comment
Share on other sites

Just done a perl script to send backups to an external drive. Works pretty well for my needs.

Here's the code. Someone might find it useful.


#!/usr/bin/env perl -w

use strict;

use warnings;

use DirHandle;

#use Compress::ZLib;

use Archive::Zip qw (:ERROR_CODES);

use File::Copy;

use POSIX;



#Declarations

sub main(@);

sub getLastFile (@);

sub copy_recursively;

sub compress (@);





#Main program call

main();





sub main (@) {

	

	#Source folder

	my $dir = '/Volumes/Server HD/Library/FileMaker Server/Data/Backups/dbFolder';

		

	#getting last created folder

	my $newest = getLastFile ($dir);

	

	#creating the destination zip filename

	my $fn_body = "a_filename";

	my $suffix = "_" . POSIX::strftime('%Y%m%d', localtime) . ".zip";

	my $dir_to = '/Volumes/usb_hd_raid/backups/fm/';

	

	my $fn_full = $dir_to . $fn_body . $suffix;

	

	

	my ($source, $target) = ($newest, $fn_full);

	

	#my $re = qr/".*"/;

	#copy_recursively ($source, $target, $re);	

	

	

	print "Compression of $fn_body started.n";

	compress ($source, $target);

	print "Compression donen";

	

}



#Returns the fullname of the last file in a given folder.

sub getLastFile (@){

	my $dir = $_[0];

	my $dir_handle = new DirHandle $dir or die "Unable to open $dir $!";

	my $file;



	my %newest; #Hash declaration



	$newest {mtime} = 0; #Set key mtime to 0



	while (defined($file = $dir_handle->read)){

		next if ($file eq '.' or $file eq '..');

		my $mtime = (stat("$dir/$file"))[9]; #Gets the modification time

		$newest {file} = $file and $newest{mtime} = $mtime if $newest{mtime} < $mtime;

	}

	

	return $dir . "/" . $newest{file};

}



#Create a Zip file from the given source and to the targeted file.

sub compress (@) {

    my $src = $_[0];

    my $dst = $_[1];

    

    my $zip = Archive::Zip->new();

    

    #Add a directory

    my $dir_member = $zip->addTree($src);   

    

    

    #save zip file

    unless ($zip->writeToFileNamed($dst) == AZ_OK)

    {

        die "read error $!";

    }      

}

Edited by Guest
Link to comment
Share on other sites

This topic is 5016 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.