Vi editor auto backup


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Vi editor auto backup
# 1  
Old 09-28-2015
Wrench Vi editor auto backup

Hi

I am looking for some option in vi config options to set so that any time any user update/change any file then one backup file (before change) is created automatically which can be used for diff or to revert back during any issue of accidental or wrong update

I had heard some option to setup backupdir etc but not able to find the detail and not able to make it working on my unix box.

Could someone pls help me with command or steps to do it

Thanks
rel
# 2  
Old 09-28-2015
Hello reldb,

Following are the 2 ways which you may try.
1st: You can create your .vimrcfile in your home directory.
example:
Code:
cat  >.vimrc
set backup " backup on
OR
cat  >.vimrc
set nobackup " backup off

Note: vim takes your .vimrc vim from your home directory. If you want backup file from VIM. use the above options in your .vimrc file. Double quote" is comment line in .vimrc file. So you can put any one of the above commands to set OR not to set backup. If you want to specify the backup files directory. Use the following way.

Code:
set backupdir=./.backup
set directory=./.backup

2nd: You can do a :w Input_file_bkp before start editing the original Input_file.
But obviously 1st option is much better than this.

Hope this helps you.

Thanks,
R. Singh
# 3  
Old 09-28-2015
Quote:
Originally Posted by reldb
I am looking for some option in vi config options to set so that any time any user update/change any file then one backup file (before change) is created automatically which can be used for diff or to revert back during any issue of accidental or wrong update
In a real vi there is no such option. There are many vi-clones out there (one being vim, which RavinderSingh13 already mentioned) which implement such a functionality, but the real vi doesn't.

The most obvious reason is that it is not needed: UNIX has a revision control system ("sccs", "Source Code Control System") built in which you could use to go back to an (in fact: any) earlier version. Many of todays UNIXes do not have sccs but one of its descendants: rcs, cvs, git, ... . If such a system is not already installed on your system it could be easily done so in a second, probably only install one or two packages and you are all set.

If you still want to do it without a version system: use a small script, which you can put into your path before vi, use an alias or whatever suits you:

myvi.sh:
Code:
#!/bin/sh

# comment the following out if you want your backups in a central backup directory:
# fBackupDir="/path/to/backupdir"

arg=""

for arg in $* ; do
     if [ -f "$arg" ] ; then
          cp "$arg" "$arg".sav
          # reverse comments for central backup dir:
          # cp "$arg" "$fBackupDir/${arg##*/}"
     fi
done

exec /usr/bin/vi $*

I hope this helps.

bakunin

Last edited by bakunin; 09-28-2015 at 09:52 AM..
This User Gave Thanks to bakunin For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Howto auto boot SPARC | How to auto supply "start /SYS" and "start /SP/console" commands

When I power ON my T4-1, I got a prompt -> where I have to start /SYS and start /SP/console. How can I auto supply these two commands ? (3 Replies)
Discussion started by: z_haseeb
3 Replies

2. Shell Programming and Scripting

Auto-backup script

hello guys i need a script to automatically backup a whole directory in linux like /var/www and the whole sql db and upload to an ftp server daily (as a cron job) is there something like this? I read about rsync but I don't know if it will suit this. (6 Replies)
Discussion started by: galapagos8000
6 Replies

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

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

5. Solaris

Epic Editor was not able to obtain a license for your use. Feature Epic Editor :Licen

Epic Editor was not able to obtain a license for your use. Feature Epic Editor :License server is down (1 Reply)
Discussion started by: durgaprasadr13
1 Replies

6. Shell Programming and Scripting

set EDITOR=vi -> default editor not setting for cron tab

Hi All, I am running a script , working very fine on cmd prompt. The problem is that when I open do crontab -e even after setting editor to vi by set EDITOR=vi it does not open a vi editor , rather it do as below..... ///////////////////////////////////////////////////// $ set... (6 Replies)
Discussion started by: aarora_98
6 Replies

7. UNIX for Dummies Questions & Answers

Pasting text in VI editor from a different editor

Hi, I knw its a silly question, but am a newbie to 'vi' editor. I'm forced to use this, hence kindly help me with this question. How can i paste a chunk 'copied from' a different editor(gedit) in 'vi editor'? As i see, p & P options does work only within 'vi'. (10 Replies)
Discussion started by: harishmitty
10 Replies

8. UNIX for Dummies Questions & Answers

Check backup file size on backup tape

Hi, I performed backup on tape and I want to append more files to my previous backup on the same backup tape. But before I do that I need to know the backup file size of the first backup I performed so that I know the available size on the backup tape. Can someone help me what command I will use... (0 Replies)
Discussion started by: ayhanne
0 Replies
Login or Register to Ask a Question