Combination backup/VI script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combination backup/VI script
# 1  
Old 01-21-2009
Combination backup/VI script

I was needing a script that basically covers my butt, lol. I have the nasty habit of making many changes without backing up files, and then after a ton of changes, if I have to go back to the original version, it makes it harder to go back.

Now, I have a script that takes a file, renames it to filename.bak.datestamp, but I was wondering how I would go about making a combination script.

I use vi to edit most files, so I'd like to use an alias 'vib'. I'd like to be able to use it in this way:

vib filename.txt

I'd like it to call a script that first runs the backup script, then runs the vi command.

Anyone done this before?
# 2  
Old 01-21-2009
Well.. I am not able to test it right now, but something like this should suffice.

Code:
function vib() {
    if [ -z $1 ]; then
        echo "You must supply a filename to modify.";
        echo "Syntax is: vib filename";
        exit;
    fi
    if [ ! -z $1 ]; then
        cp -v $1 /home/username/pathtobackupdir/$1.bak.`date +%Y%m%d`
        vi $1
    fi
}

Let me know how it works out! Of course, change the path to the backup directory.
# 3  
Old 01-21-2009
You mean something like
Code:
for file in "$*"
do
    cp ${file} ${file}.`date +%Y-%m-%dT%H:%M:%S`
done
vi "$*"

Personally, I rather prefer svn (or any other RCS) over the copy-backup method for such things.
# 4  
Old 01-22-2009
Quote:
Originally Posted by pludi
You mean something like
Code:
for file in "$*"
do
    cp ${file} ${file}.`date +%Y-%m-%dT%H:%M:%S`
done
vi "$*"

Personally, I rather prefer svn (or any other RCS) over the copy-backup method for such things.
Works perfectly.

I might have used the first posters, but the server is pretty consolidated, with different backup directories for different applications, so it would have gotten much more complicated to work all that into it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

PHP parametric + bash script combination

Hello, I have a simple bash script and I manually run this script to put a file into related directory in apache normally. I need to run it in php with parameter. My target is to get a download link by running below script but I do not know anything about php. Here is my bash script: run.sh... (6 Replies)
Discussion started by: baris35
6 Replies

2. Shell Programming and Scripting

Basic Combination Shell Script

I need to have a script read a file that has a list of words in a single column like below:Black Blue Brown Orange Red Yellow Green White Purple Silver Grey Tan Then print to another file just all of the two-word possible combinations. Example: Black,Blue Anyone want to take a... (4 Replies)
Discussion started by: vespasian
4 Replies

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

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

5. Shell Programming and Scripting

Arbitrary permutation and combination script

#!/bin/bash # permutation_combination.sh # Version: 2.0 # Author : YongYe <complex.invoke@gmail.com> arg0=-1 argv=${3} number=${2} eval ary=({1..${1}}) length=${#ary} percom(){ nsloop i ${1} number${2} ${3} ${4} ${5}; } invoke(){ echo $(percom ${argu} nsloop -1) prtcom $(percom... (1 Reply)
Discussion started by: complex.invoke
1 Replies

6. Shell Programming and Scripting

Backup script / Test if script is already running

Hello everyone, I have 2 questions : 1) I have a backup shell script, let's call it backup.sh, that is called every hour as a cron job. As a matter of fact a backup could last more than one hour. It mounts a NAS and then do some rsync on important directories, so really I don't want to... (2 Replies)
Discussion started by: freddie50
2 Replies

7. Shell Programming and Scripting

Select combination unique using shell script

Hi All, bash-3.00$ gzgrep -i '\ ExecuteThread:' /******/******/******/******/stdout.log.txt.gz <Jan 7, 2012 5:54:55 PM UTC> <Error> <WebLogicServer> <BEA-000337> < ExecuteThread: '414' for queue: 'weblogic.kernel.Default (self-tuning)' has been busy for "696" seconds working on the request... (4 Replies)
Discussion started by: osmanux
4 Replies

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

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

10. Shell Programming and Scripting

Combination of case and If else in shell script

Would it be right forme to combine case statement and if else in one shell script? Would it work? (2 Replies)
Discussion started by: Pauline mugisha
2 Replies
Login or Register to Ask a Question