views:

65

answers:

3

It tells me I have bad syntax on the line:

rsync -a --delete #{DIR_DATA}/ #{todays_folder}/

Here's the entire program:

#!/usr/bin/ruby
require 'rubygems'
require 'fileutils'


DIR_DATA="/mnt/apvdbs03/Public"
DIR_BKUP_ROOT="/backs/apvdbs03"
NUMBER_OF_BACKUPS = 7

def remove_last_backup_folder
last_backup_folder = File.join(DIR_BKUP_ROOT, NUMBER_OF_BACKUPS.to_s)
FileUtil.rm_rf last_backup_folder
end

def roll_backup_folders_forward
  NUMBER_OF_BACKUPS.downto(0) do |i|
    old_backup_folder = File.join(DIR_BKUP_ROOT, (i - 1).to_s)
    new_backup_folder = File.join(DIR_BKUP_ROOT, i.to_s)
    File.mv old_backup_folder new_backup_folder if File.exist(old_backup_folder)
end

def yesterdays_folder 
  @yesterdays_folder ||= File.join(DIR_BKUP_ROOT, 1)
end

def todays_folder
  @todays_folder ||= File.join(DIR_BKUP_ROOT, 0)
end

def hard_link_yesterdays_folder
  `cp -al #{yesterdays_folder} #{todays_folder}`
end

# rm -rf backup.3
remove_last_backup_folder

# mv backup.2 backup.3
# mv backup.1 backup.2
roll_backup_folders_forward

# cp -al backup.0 backup.1
hard_link_yesterdays_folder

# make todays backup
`rsync -a --delete #{DIR_DATA}/ #{todays_folder}/`
A: 

you haven't closed your last def, so an end needed after rsync line

KARASZI István
that got rid of that error. I've apparently got other bugs with my code. The script runs, but does nothing that I expected. I don't have any idea what is wrong.
Captain Claptrap
then could you update the OP?
KARASZI István
+1  A: 

It looks like this block is never closed:

NUMBER_OF_BACKUPS.downto(0) do |i|
  . . .
end # Missing!
DigitalRoss
A: 

File.join("root",1.to_s) returns "root/1", not "root.1" as the comments indicate.

AShelly