Help required to get a backup script working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help required to get a backup script working
# 1  
Old 11-24-2016
Help required to get a backup script working

Hi all

I have a unix based firewall, which creates a daily backup file on the device.

I need a script to scp this file over to a remote server.

I can get this working daily using a basic script and a cron job.

However, I only want it to send the latest config back up file and currently it is sending across everything is the source directory.

How can I amend the script to just send the latest?

Thanks




James
# 2  
Old 11-24-2016
Welcome jimmyzoom ,

I have a few to questions pose in response first:-
  • What have you tried so far?
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • Do you have SSH keys exchanged allowing a password-less scp?
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)
Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.


Without seeing your script, it is difficult to suggest how to change it. Can you post it? Please wrap it in CODE tags so it displays properly.


Kind regards,
Robin
# 3  
Old 11-25-2016
If you use a standard tool like rsync, you can have it only backup files in the src directory that are new, meaning that were not there the last time the backup was run. If your "latest config back up file" has a different name than the files that have already been copied, rsync (or many other backup programs) will automatically do what it sounds like you want. If the "latest config back up file" has the same name as a file that already exists in the mirror location, rsync will rename the older file (the one in the mirror location) with an extension you provide. If you want to have multiple incremental backups of a file with the same name, that can probably be done as well but I prefer to rename older versions of a file for clarity and book keeping purposes.

As rbatte1 suggests, more information would be helpful. At any rate, a backup solution should be designed with your recovery process in mind. What files you store, and where, and what they are called, etc, depends somewhat on the process you will need to involve should you ever have to use your backup files.

You will want a script to run that end of the business as well, and definitely practice using it before you need to use it.

LMHmedchem
This User Gave Thanks to LMHmedchem For This Post:
# 4  
Old 11-25-2016
One more point, in addition to what has been said:

You need to define, what you mean by "latest". The one having the most recent modification time, or the one having a "most recent" timestamp embedded in the file name?

I found that in practical applications, the latter is used more often, because it is too easy changing the modification time of an old file to a new value by accidentally touching it. Writing a backup script of course depends on how you define the "latest" file.
This User Gave Thanks to rovf For This Post:
# 5  
Old 11-25-2016
Personally, i think that using dates (or other form of timestamps) in filenames is not necessarily a good idea: the advantage of knowing when it was created/last modified without relying on inode information is somewhat alleviated by the unability to restrict the creation of files to a certain number of generations.

The usual case is like this: create a daily backup and keep a certain number of generations (say: 5). One option is to create a script creating a timestamp-named output file and then another script to delete the 6th-oldest such file (if it exists). Run both scripts daily. Possible problem: the second script is oftenly forgotten and the backups fill up your diskspace.

Another option is to create a file with a fixed name and apply logic to rename this file until a name for deletion is reached after a certain number of generations:

Code:
#! /bin/ksh

if [ -e /some/where/4th_gen ] ; then
     mv /some/where/4th_gen /some/where/5th_gen
fi
if [ -e /some/where/3rd_gen ] ; then
     mv /some/where/3rd_gen /some/where/4th_gen
fi
if [ -e /some/where/2nd_gen ] ; then
     mv /some/where/2nd_gen /some/where/3rd_gen
fi
if [ -e /some/where/1st_gen ] ; then
     mv /some/where/1st_gen /some/where/2nd_gen
fi

my_backup_process > /some/where/1st_gen

exit 0

Advantage: you only need one script and you never have to bother with a process filling up your diskspace with numbers of old backups.

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

RHEL 7: Backup Space and Delete is not working in console

Hi All, During my virtual machine power on i have rc3.d script to accept user inputs like IP address. This script gets executed during first time boot up. It was working fine till my VM is using RHEL6.5. Now we migrated to RHEL 7 environment. While accepting the user inputs in console, I... (4 Replies)
Discussion started by: kalpeer
4 Replies

2. Shell Programming and Scripting

Percona SQL Backup Shell Script not working

I am having one heck of a time, and I need anyone that can assist in finding my issue here.... First off, here is the script we are using: pastebin dot com slash njwUg6vd All usernames and passwords have been edited out. We are using an actual database user, and not root (tried both). I... (0 Replies)
Discussion started by: jonbeard
0 Replies

3. AIX

GTAR - new ways to faster backup - help required

We are taking backup of our application data(cobol file system, AIX/unix) before and after EOD job runs. The data size is approximately 260 GB in biggest branch. To reduce the backup time, 5 parallel execution is scheduled through control-m which backups up the files in 5 different *.gz. The job... (8 Replies)
Discussion started by: Bharath_79
8 Replies

4. AIX

GTAR - new ways for faster backup - help required

We are taking backup of our application data(cobol file system, AIX/unix) before and after EOD job runs. The data size is approximately 260 GB in biggest branch. To reduce the backup time, 5 parallel execution is scheduled through control-m which backups up the files in 5 different *.gz. The job... (2 Replies)
Discussion started by: Bharath_79
2 Replies

5. Shell Programming and Scripting

Help with Backup Shell Script for Network Device Configuration backup

HI all, im new to shell scripting. need your guidence for my script. i wrote one script and is attached here Im explaining the requirement of script. AIM: Shell script to run automatically as per scheduled and backup few network devices configurations. Script will contain a set of commands... (4 Replies)
Discussion started by: saichand1985
4 Replies

6. Shell Programming and Scripting

Script not working in cron but working fine manually

Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered. The script is as follow: #!/bin/sh for file in file_1.txt file_2.txt file_3.txt do awk '{ print "0" }' $file > tmp.tmp mv tmp.tmp $file done And the cron... (2 Replies)
Discussion started by: jasperux
2 Replies

7. Shell Programming and Scripting

Script is not working from cron while working manually

Hello, I am facing a very strange problem when I run my script manuallu ./Fetchcode which is using to connect with MKS integrity from linux end it workks fine but when I run it from cron it doesn't work.Can someone help me 1) How could I check my script when it is running from cron like... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

8. Shell Programming and Scripting

rsync backup mode(--backup) Are there any options to remove backup folders on successful deployment?

Hi Everyone, we are running rsync with --backup mode, Are there any rsync options to remove backup folders on successful deployment? Thanks in adv. (0 Replies)
Discussion started by: MVEERA
0 Replies

9. Shell Programming and Scripting

Backup script not working

Hi guys iv been working on a bit of script to do a backup and restore Im going to uni next year and trying to prepare myself Basically all im wanting is a simple script that shows a menu and does what ever the user inputs here is my code #!/bin/sh # Backup des backup= "/root/Russell/"... (2 Replies)
Discussion started by: rustyhamster
2 Replies

10. UNIX for Dummies Questions & Answers

Backup Rationalisation Script - Help Required

Ok so once again im back with what is probably a beginner question although somewhat more complicated (for me) than the last. Background: A client has a daily backup which is carried out via rsync. Due to this, when they move a file around that file is then coppied a second time. On top of... (4 Replies)
Discussion started by: jeked
4 Replies
Login or Register to Ask a Question