Visit Our UNIX and Linux User Community


backup a file and keep every version of the backup


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users backup a file and keep every version of the backup
# 1  
Old 01-19-2011
backup a file and keep every version of the backup

I am trying to backup my .bash_history and I want to keep every version of the backup. I am thinking to put one of these in my crontab.

Code:
0 0 * * 0,3 cat .bash_history > boo
0 0 * * 0,3 cp .bash_history boo

I would like the backups to be called boo1, boo2, boo3, etc. I would like to keep every version of the backup. So how would I go about changing this?
# 2  
Old 01-19-2011
Instead of making boo1, boo2 etc. I'd suggest you to create file names with boo_<date> ; eg. today's file would be boo_20110119. It would be easier to identify also.

Try this:

Code:
0 0 * * 0,3 cp .bash_history boo_$(date +%Y%m%d)


But if you specifically want _1, _2 etc. you can write a small script to get the latest boo_* file, then cut the string after '_' , add 1 to that cut string as it would be a number, and create file with that name...

Put that shell script in cron
# 3  
Old 01-19-2011
Quote:
Originally Posted by freakygs
Instead of making boo1, boo2 etc. I'd suggest you to create file names with boo_<date> ; eg. today's file would be boo_20110119. It would be easier to identify also.

Try this:

Code:
0 0 * * 0,3 cp .bash_history boo_$(date +%Y%m%d)

But if you specifically want _1, _2 etc. you can write a small script to get the latest boo_* file, then cut the string after '_' , add 1 to that cut string as it would be a number, and create file with that name...

Put that shell script in cron
Thx. Could you also explain how to write that script?
# 4  
Old 01-19-2011
Code:
a=`ls -rt ~/boo* 2>/dev/null | tail -1 | awk -F"_" {'print $NF'}`
a=`expr ${a:-0} + 1`
cp ~/.bash_history ~/boo_$a

# 5  
Old 01-20-2011
Quote:
0 0 * * 0,3 cp .bash_history boo_$(date +%Y%m%d)
This line will not work for the following reasons:
A percentage sign must be escaped in a crontab because "%" has special meaning in a crontab.
The filenames need to be full hierarchial names in this context.

---------- Post updated at 16:25 ---------- Previous update was at 16:18 ----------

What are the settings of all the HIST* environment variables in your .bashrc file? If they are not correct you will not retain all your history.

Imho the best way to save history is to change the value of $HISTFILE to make the filename unique (i.e. include date, time and terminal id).
# 6  
Old 02-02-2011
Quote:
Originally Posted by methyl
This line will not work for the following reasons:
A percentage sign must be escaped in a crontab because "%" has special meaning in a crontab.
The filenames need to be full hierarchial names in this context.

---------- Post updated at 16:25 ---------- Previous update was at 16:18 ----------

What are the settings of all the HIST* environment variables in your .bashrc file? If they are not correct you will not retain all your history.

Imho the best way to save history is to change the value of $HISTFILE to make the filename unique (i.e. include date, time and terminal id).
Is this bad? Thats whats in my .bashrc.

Code:
HISTSIZE=9000 
HISTCONTROL=ignoreboth
source hist

# 7  
Old 02-02-2011
To reiterate.
Imho the best way to save history is to change the value of $HISTFILE to make the filename unique (i.e. include date, time and terminal id).

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Backup file

Im a fairly new linux user and im trying to learn how to do a backup shell script. i have this so far, #! /bin/bash backup_files="/home/clint/music" dest="home/clint/backups' day=$(date +%A) hostname=$(hostname -s) archive_file="$hostname-$day.tgz" tar czf $dest/$archive_file... (2 Replies)
Discussion started by: thatdudeman
2 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. UNIX for Dummies Questions & Answers

Copy file from a backup tape

I have several files that I need to get off of a backup tape. I'm using AIX 4.3 (I know this is old) and our backups are done using the bru command. I need to copy these files to a specific location, and not restore them to the original location. Can anyone tell me what command I should use to do... (4 Replies)
Discussion started by: troy
4 Replies

5. Shell Programming and Scripting

File Backup - TAR help

Hi, Another rookie here. I have a script I am developing to backup files from various directories onto a windows machine. Script description: - mv files from various directories - tar all files in that directory - export to windows server for safe keeping, external backups. The... (5 Replies)
Discussion started by: mcclunyboy
5 Replies

6. Shell Programming and Scripting

Backup of today's file

Hiii, Here is the part o fmy script- for file in $FileList do if ]; then echo "Skips $file file. It is todays file" if ];then cp $file $BackupLocation 2>/dev/null ... (3 Replies)
Discussion started by: namishtiwari
3 Replies

7. SCO

Backup to SCSI Tape Backup aborts

I am trying to make a full backup of my system using the cpio command. The Tape Unit is a SCSI DDS. The process started fine but after about 30 minutes, it just stopped and showed the following message: 1755 Signal 31 - Core dumped Any idea of what is causing this and how to fix it? ... (4 Replies)
Discussion started by: zionpc
4 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

9. AIX

200GB file backup

Dear All, I have 200GB mount point, but i have only 94GB files. i am taking this files as a tar with gzip backup. but my problems is if this files will be Reach 150GB or more what can i do? Please advice me can i use tar backup or any other tool for the backup. thanks in... (5 Replies)
Discussion started by: rkgali
5 Replies

Featured Tech Videos