Sponsored Content
Full Discussion: Smart Backup Script
Top Forums Shell Programming and Scripting Smart Backup Script Post 302467843 by TheGacko on Sunday 31st of October 2010 07:05:13 PM
Old 10-31-2010
Smart Backup Script

Hello

Im pretty new to scripting in linux but am keen to learn.

I'm trying to create a backup script similar to a batch script I developed for windows (dos) where the backup is to a usb drive. no problems with the backup process but what I would like to do is automatically remove old files if say less 20 gigabytes (or any hard coded number) is available.

What I did with the windows script was have a if statement check if 20g was available if not remove the oldest backup then check again then remove the oldest again etc. It used goto commands to loop which I know is ugly and there is no equivalent in the linux bash world.

I think i have the core parts of the script down pat which Ill list below but the loop part to go back and check im not sure about. should I be using a for loop?? or something else?

one liner to give me the free space available on usb drive
Code:
df |grep usb |awk '{print $4}'

one liner to remove oldest backup file (tgz file)
Code:
ls -S *.tgz |tail -n1 |xargs rm

one liner to check if space is less than hard code number (or ideally variable) using the above
Code:
if [ $(df |grep usb |awk '{print $4}') -lt 20000000 ]; then ls -S *.tgz |tail -n1 |xargs rm; fi

I know I should be building this all into functions. could someone help with this??

---------- Post updated at 12:05 PM ---------- Previous update was at 09:39 AM ----------

basically after ive sent the last command I posted (all in one line command) how do I then say go back and check again

check if 20G available
>> if not go back, remove another file and check again
>> if so, 20G is available carry on and do the backup

I used to use a goto command in the windows batch script I used but this isn't available in BASH.. I know its possible but am just wanting pointers or example scripts on how to loop this

doing it this way is quite nice as then im not reliant on whatever capacity drive a user may put in it will always make space on the device. with a few other checks in place as well.
 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

smart script?

First, I know that's a bad title. I couldn't think of anything short enough. ... I wrote the following script to let me know when various parts of the network are down. It used to look like this before last weekend when I got over 500 emails about 1 host being down all weekend: this is in the... (1 Reply)
Discussion started by: raidzero
1 Replies

2. UNIX for Dummies Questions & Answers

Explain the difference between the commands cd ~smart and cd ~/smart

Is it possible for both commands to work? (1 Reply)
Discussion started by: phunkypants
1 Replies

3. 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

4. Shell Programming and Scripting

Need help in creating file restoration script from a backup script.

Hi all i am struggling in creating a restore of env files while doing applications clone. the first file i created for copying the important configurations file which is running perfect now for reverting the changes i mean when i am restoring these files to its original places i have to do... (7 Replies)
Discussion started by: javeedkaleem
7 Replies

5. Shell Programming and Scripting

Need smart script !

Hi, I need a script to assign variables the below paths /appl/user_projects/domains/<xxx>/servers/<yyy>/logs Where <xxx> can be any number and name of directories. <yyy> can be another set of any number of names and directories. I want to neglect all the <xxx> and <yyy>... (3 Replies)
Discussion started by: mohtashims
3 Replies

6. 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

7. Shell Programming and Scripting

Shell script to call Oracle archive backup script when file system reaches threshold value

Hello All, I need immediate help in creating shell script to call archivebkup.ksh script when archive file system capacity reaches threshold value or 60% Need to identify the unique file system that reaches threshold value. ex: capacity ... (4 Replies)
Discussion started by: sasikanthdba
4 Replies
svn-fast-backup(1)					      General Commands Manual						svn-fast-backup(1)

NAME
svn-fast-backup - very fast backup for Subversion fsfs repositories. SYNOPSIS
svn-fast-backup [-q] [-k{N|all}] [-f] [-t] [-s] repos_path backup_dir DESCRIPTION
svn-fast-backup uses rsync snapshots for very fast backup of a Subversion fsfs repository at repos_path to backup_dir/repos-rev, the latest revision number in the repository. Multiple fsfs backups share data via hardlinks, so old backups are almost free, since a newer revision of a repository is almost a complete superset of an older revision. This is good for replacing incremental log-dump+restore-style backups because it is just as space-conserving and even faster; there is no inter-backup state (old backups are essentially caches); each backup directory is self-contained. It has the same command-line interface as svn-hot-backup(1) (if you use --force), but only works for fsfs repositories. svn-fast-backup keeps 64 backups by default and deletes backups older than these; this can be adjusted with the -k option. OPTIONS
-h, --help Shows some brief help text. -q, --quiet Quieter-than-usual operation. -k, --keep=N Keep a specified number of backups; the default is to keep 64. -k, --keep=all Do not delete any old backups at all. -f, --force Make a new backup even if one with the current revision exists. -t, --trace Show actions. -s, --simulate Don't perform actions. AUTHOR
Voluntary contributions made by many individuals. Copyright (C) 2006 CollabNet. 2006-11-09 svn-fast-backup(1)
All times are GMT -4. The time now is 04:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy