Script or alias to backup all files opened by vi


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script or alias to backup all files opened by vi
# 1  
Old 03-14-2014
Script or alias to backup all files opened by vi

we want to backup all opened files by vi before editing also with version information. i wrote below alias to backup crontab file content with version info. What i want know is to make this opened files by vi. We want to prevent user mistakes by adding this alias.

alias crontab='DATE=$(date +"%Y%m%d%H%M");cp /var/spool/cron/crontabs/root /var/spool/cron/crontabs/root.bck$DATE;crontab'

Thanks,
regards.
# 2  
Old 03-14-2014
I guess vim (Vi IMproved) has an option to take backup or incremental backup when editing a file.
# 3  
Old 03-18-2014
Something like this might help:-
Code:
print ":w .profile.`date +%s`" > /tmp/$$ ; vim -s /tmp/$$ .profile;rm /tmp/$$

It might be fun getting it into an alias though. It also only works on a single file. I suppose you could write it as a shell script and put in a loop, calling your shell script in place of vim



I hope that this helps,
Robin
Liverpool/Blackburn
UK
# 4  
Old 03-18-2014
@yoda, rbatte1, thanks for the replies.
i forgot to add OS information. Servers are AIX and HPUX. i installed vim to one server. i couldnot restore from backup or a version also it is not practical to install vim to all servers. i ll try to find another solution

Thanks

Last edited by sebu; 03-18-2014 at 10:47 AM.. Reason: sth
# 5  
Old 03-18-2014
I used to have a shell script for working on source, vis, that wrapped vi and looked for an S directory next to the target file, and files that were writable. If it found these, it checked the file into SCCS in an s.same_name in the S dir before and after editing, if the file was out of sync with the latest in SCCS. This way, I could avoid commenting out everything old into clutter. You need a tool like sccs, and a little scripting. You need code for the first pass, when there is no sccs file, as well as for the times it changes. You can choose to create the S dir as well, for any writable file edited by 'vis'. (Used to be called vim for vi my source, but someone took that!)

I think there are file systems that create version suffixes every time you modify a file. Versioning file system - Wikipedia, the free encyclopedia

One system did daily backups and left the old or hard linked current versions in shadow directories under N .snapshotN/ dirs for N days.
This User Gave Thanks to DGPickett For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Solaris 11 - opened files limit ?

Hey all, I'm running apache (cswapache2) on a Solaris 11.3 server. Recently, if I create a new vhost, the service fails to restart, and enters in maintenance mode. If I comment lines with log files, the service starts again. I guess I've reached the limit. I checked the current values... (8 Replies)
Discussion started by: omegared77
8 Replies

2. Shell Programming and Scripting

Create a list of files from alias by script

Actually I have many pictures with diferent name and size around 2000, I need generate a copy of them from one list of alias. The structure of the list is something like this: alias_list.txt <01>randomname.png<02> Randomname.png RandoMname.png RandOmname.png RandomnamE.png... (6 Replies)
Discussion started by: Tapiocapioca
6 Replies

3. Shell Programming and Scripting

Simple .sh and alias or ? whatever. Do backup!

Hi , Using bash shell (mintty) in cygwin/windows env. for some time and having issues with most basic commands. Will be quite easy to get er done once I know how , just like magic tricks. I need either alias OR shell script to change windows to posix path AND put that line back -input OR .cd to... (2 Replies)
Discussion started by: sircuts
2 Replies

4. Shell Programming and Scripting

File exists, but cannot be opened.How to check- whether it could be opened to read when it exists

Hi #Testing for file existence if ; then echo 'SCHOOL data is available for processing' else echo 'SCHOOL DATA IS NOT AVAILABLE FOR PROCESSING' : i wrote a script, where it begins by checking if file exists or not. If it exists, it truncates the database... (2 Replies)
Discussion started by: rxg
2 Replies

5. UNIX for Dummies Questions & Answers

Create alias files (not alias commands)

If one: $ find -name 'some expression' -type f > newfile and then subsequently wants to create an alias file from each pathname the find command retrieved and the > placed within 'newfile', how would one do this? Ideally, the newly created alias files would all be in one directory. I am... (3 Replies)
Discussion started by: Alexander4444
3 Replies

6. UNIX for Advanced & Expert Users

Number of files currently opened in linux

Hello, How do i check number of files currently opening in the linux server? Your help is highly appreciated. Thank you ---------- Post updated at 02:43 PM ---------- Previous update was at 02:19 PM ---------- never mind!! I got it. ---------- Post updated at 02:44 PM ---------- Previous... (3 Replies)
Discussion started by: govindts
3 Replies

7. Shell Programming and Scripting

script compare files and backup

Im working on a shell script that uses three parameters, a string to replace, the string replacing, and a file name. In this script it makes a back up file before the replacement occurs. However I want to be able to either search the file to see if it has the string and if it doesnt dont create... (5 Replies)
Discussion started by: gordonheimer
5 Replies

8. Shell Programming and Scripting

Script to Backup files

Hi, I wrote a simple script to backup of index.php and index.html in my box. So, I wrote a script which take a copy of the index page as 1Mar09: but it does not comes up.. #! /bin/bash find . -name index.* > domains.txt for i in `cat domains.txt` ; do cp index* index*.1Mar09 $i; done But... (6 Replies)
Discussion started by: gsiva
6 Replies

9. Shell Programming and Scripting

multiple files opened in awk

Hi , i' d like to use an awk script to automate the ripping of cds : here's how it works : - i first create a file named songs.txt containing the name of the songs - the scripts extracts the tracks of a cd with cdparanoia - the scripts saves the contents of the dir with ls (ls > list.txt) -... (0 Replies)
Discussion started by: krhamidou
0 Replies

10. HP-UX

How to get the opened files by a process

Hi, i'd like to get the files which are opened by a process during his execution using the c language. Thanks for helping me. (2 Replies)
Discussion started by: benoit.gaillard
2 Replies
Login or Register to Ask a Question