Need help with my backup AS ...please help

Hi guys,

I’m very new at Applescript, so please forgive me if my question is very obvious.

I’m making a simple backup script that logs in via SSH to my local linux server, tars a directory and secure copies the tar file back to my Mac.

This is what I’ve done so far:


tell application "Terminal"
	activate
	try
		do script "ssh my.linuxserver.com -l username" in window 1
		delay 15
		do script "type_password" in window 1
	on error
		display dialog "Couldn't connect to server" buttons {"Oops!"} default button 1
	end try
end tell
delay 2
tell application "Terminal"
	do script "su" in window 1
	delay 2
	do script "type_password" in window 1
	delay 2
	do script "cd /usr/local" in window 1
	delay 1
	do script "tar -cf cvsroot_newbackup.tar ./cvsroot" in window 1
	delay 15
	do script "scp ./cvsroot_newbackup.tar username@my.mac.com:/Path/to/backupdir" in window 1
	delay 10
	do script "type_password" in window 1
	delay 200
	do script "rm -f ./cvsroot_newbackup.tar" in window 1
	do script "exit" in window 1
	do script "exit" in window 1
end tell
tell application "Terminal"
	quit
end tell

At the end of this script I would like to rename the file ‘cvsroot_newbackup.tar’ to something like ‘cvsroot_20040705.tar’ where ‘20040705’ stands for the current date (yearmonthday). Naturally I would like AS to determine the current date by itself.

Can anybody please help me out with this?

Thanks in advance!

Is there nobody that can help me with this question? :cry:

Is my question too complex or too easy? :rolleyes:

try this:

set thisMonth to (month of (current date) as number) as string
if thisMonth < 10 then set thisMonth to “0” & thisMonth
set thisDay to day of (current date) as string
if thisDay < 10 then set thisDay to “0” & thisDay

set newName to “cvsroot_” & ((year of (current date)) as string) & thisMonth & thisDay & “.tar”

tell application “Finder” to set name of file “Users:yourName:FileNameOld.rtf” to newName

iBackup, Thanks alot man! You just made my day!

I had to remove the ‘as string’ parts behind the month and day rules, but other than tat it works like a charm!

Thaaaaaank you!!! :smiley:

New version

set thisMonth to (month of (current date) as number)
if thisMonth < 10 then set thisMonth to "0" & thisMonth
set thisDay to day of (current date)
if thisDay < 10 then set thisDay to "0" & thisDay
set newName to "cvsroot_" & ((year of (current date)) as string) & thisMonth & thisDay & "01.tar"
tell application "Finder" to set name of file "Path:to:cvsroot_newbackup.tar" to newName