[bash] Simple backup (cp) script but incremental


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [bash] Simple backup (cp) script but incremental
# 8  
Old 08-19-2009
Note that the command copies only files newer then the reference file.
To get the desired format of the date you can use this command:

Code:
CurrDate=$(date "+%d-%m-%Y %H-%M")

Have a read of the manpage of date.

Regards
# 9  
Old 08-19-2009
I've often used
Code:
cp -Ru $source $destination

The -u flag only copies files if source is newer (ie 'update'), and you may already be familiar that -R means recursive (scans through subdirectories too).

I often include -v flag (verbos) too so you get a list of all the files being copied. thus, if you wanted the process logged, then you can redirect the output to a log file:
Code:
cp -Ruv $source $destination > /var/logs/userbackups.log

I must emphasise that I've not used this in a production environment though - only for controlled "offline" back ups. (I use ZFS snapshots on the production server). So there may be a number of disadvantages to cp -u compared with the suggestions earlier in this thread.
# 10  
Old 08-19-2009
Thanks for the replies, I am indeed familiar with cp and its options, like recursive. Having the verbose options print all the copied files would be nice in my case.
Like you said it is maybe better to not use cp; but cpio instead.
The only problem I experience now is that it doesn't copy recursive. (but only the single file in /home ; not the folders) Is there a solution to this?

Thanks in advance
# 11  
Old 08-19-2009
Quote:
Originally Posted by laurens
Thanks for the replies, I am indeed familiar with cp and its options, like recursive. Having the verbose options print all the copied files would be nice in my case.
Like you said it is maybe better to not use cp; but cpio instead.
The only problem I experience now is that it doesn't copy recursive. (but only the single file in /home ; not the folders) Is there a solution to this?

Thanks in advance
Are you shure you have newer files then the reference file?

Regards
# 12  
Old 08-19-2009
Quote:
Originally Posted by laurens
Thanks for the replies, I am indeed familiar with cp and its options, like recursive. Having the verbose options print all the copied files would be nice in my case.
Like you said it is maybe better to not use cp; but cpio instead.
The only problem I experience now is that it doesn't copy recursive. (but only the single file in /home ; not the folders) Is there a solution to this?

Thanks in advance
After checking the man pages, the only advantage of CPIO that I can see is compression.
If compression isn't an issue, then perhaps you're over engineering a solution (I'm a firm believer of KISS - automate everything, but don't build a sports car when all you need is scooter).
If compression is an issue (which I suspect it is), then perhaps it might be better looking into tar (which i believe can also do an update as well as recursive)
# 13  
Old 08-19-2009
I don't even need compression, or maybe files can be compressed but the backup'ed folders have to look like regular folders. I hope you can follow... Smilie But I'll leave it like that with cpio
@Franklin, idd, you were right the folders were older. Your script works perfect after all! Thx.
I just guessed it would first copy all the empty folders too (to have a basic structure), but in the end that's not really necessary.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Create a simple bash backup script of a file

This is the problem: Write a script that will make a backup of a file giving it a ‘.bak’ extension & verify that it works. I have tried a number of different scripts that haven't worked and I haven't seen anything really concise and to the point via google. For brevity's sake this is one of the... (4 Replies)
Discussion started by: demet8
4 Replies

2. Homework & Coursework Questions

incremental or full backup ???

Hi. Can someone tell me if the following script that i have made is a script for INCREMENTAL BACKUP or FULL BACKUP. My teacher told me that is doing an FULL BACKUP. • find /etc /var /home -newer /backups/.backup_reference > /backups/.files_to_archive • touch /backups/.backup_reference • tar... (1 Reply)
Discussion started by: bender-alex
1 Replies

3. UNIX for Dummies Questions & Answers

incremental and full backup.. please help me

Hi, i'm new here(and a newbie) and i need some help with a project. I need to write a script for an incremental backup (this must be executed every day at 24:00) and a full backup (executed once a month) for etc/var/home directories. Can someone please help me with this? And a small explanation of... (9 Replies)
Discussion started by: bender-alex
9 Replies

4. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

5. Windows & DOS: Issues & Discussions

Incremental Backup

I have a folder /root/test in a centos 5.3 system. I want to take an incremental backup of the contents of the folder in the C:\Downloads folder of a windows system present in the same lan as the linux system. What are the ways of executing this plan? Kindly help (0 Replies)
Discussion started by: proactiveaditya
0 Replies

6. Shell Programming and Scripting

Incremental backup

Hi, I would like to create a daily incremental backup of a directory with all of the files within and add a timestamp (year-month-day) to the tar.gz file. I have the following, but it doesn't backup the inside files of the directory. #!/bin/bash tar -czf... (1 Reply)
Discussion started by: agasamapetilon
1 Replies

7. UNIX for Dummies Questions & Answers

Best unix incremental backup utility?

Hello everyone. Could you please advise of what would be the best Unix (Debian 4) program for regular (daily or weekly) incremental backups? I'm not sure whether the backups will be stored on a "backup" drive on the same system or on an external "backup" system, but we would like to have a... (2 Replies)
Discussion started by: nottrobin
2 Replies

8. UNIX for Dummies Questions & Answers

incremental backup

Hi All.. i am trying to write a script which will give the incremental tar backup of all files with latest timestam. i tried with find -mmin -2 but if it takes half on hour or something to creat the tar itself, then no meaning in using the above command. so please help me to find the... (2 Replies)
Discussion started by: Usha Shastri
2 Replies

9. Shell Programming and Scripting

tar - incremental backup

Hello everyone! I'm trying to make incremental tar archives of a folder for an example. On the box I use is UNIX AIX installed. I tried some sample codes I found on several web pages but with no success. Don't know what I'm doing wrong. Please write some sample code to make incremental tar... (0 Replies)
Discussion started by: Funky_ass
0 Replies

10. Shell Programming and Scripting

How to reinvent incremental backup in bash?

I want to backup two important files everytime they are modified. How would I write a bash script that would check the dates of my zip files and my data files and only create a new zip file if the zip file is older than the two data files? Thanks, Siegfried (1 Reply)
Discussion started by: siegfried
1 Replies
Login or Register to Ask a Question