Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-22-2011, 11:47 PM   #1
Registered: Dec 2011
Posts: 42

Rep: Reputation: Disabled
Using TAR to create backup of files created today in data directory

Using TAR command is it possible to take backup of files created today??

played around with ->

cd /opt/backup/
find . -mtime -1 -type f -print > $INPUT_FILE
for i in $(cat $INPUT_FILE); do
echo "line: $i";
tar --append --file=$OUTPUT_FILE $i

it gives me a strange and different error everytime.. any suggestions on improving the script?
Old 12-23-2011, 12:17 AM   #2
Registered: Sep 2011
Location: Pune,India
Distribution: RHEL ,CentOS, Fedora
Posts: 100

Rep: Reputation: 25

This script doesn't seem to be complete. Please paste the complete script and also paste the error message.
Old 12-23-2011, 03:04 AM   #3
LQ Newbie
Registered: Aug 2011
Posts: 9

Rep: Reputation: Disabled
i think below will help u

find . -mtime -1 -type f |xargs tar cvzf test.tar


Old 12-23-2011, 12:00 PM   #4
Satyaveer Arya
Senior Member
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,415

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
Yes, using tar command it is possible to take backup of files created today. I will give you an example of my shell script which I use for creating backup every sunday.
This is the example of my case on my server which I use it:

I had automated a little shell script that basically mounts my backup drive, checks the date, every sunday it makes a full backup of some datafiles and some configuration settings, older incremental backups are removed. other days it backups files that have been accessed the last day and at last it unmounts the backup drive.

And here is the code which I use:


DATA="/home /root /usr/local/httpd"
CONFIG="/etc /var/lib /var/named"

mount /mnt/backup
set $(date)

if test "$1" = "Sun" ; then
        # weekly a full backup of all data and config. settings:
        tar cfz "/mnt/backup/data/data_full_$6-$2-$3.tgz" $DATA
        rm -f /mnt/backup/data/data_diff*
        tar cfz "/mnt/backup/config/config_full_$6-$2-$3.tgz" $CONFIG
        rm -f /mnt/backup/config/config_diff*
        # incremental backup:
        find $DATA -depth -type f \( -ctime -1 -o -mtime -1 \) -print > $LIST
        tar cfzT "/mnt/backup/data/data_diff_$6-$2-$3.tgz" "$LIST"
        rm -f "$LIST"
        find $CONFIG -depth -type f  \( -ctime -1 -o -mtime -1 \) -print > $LIST
        tar cfzT "/mnt/backup/config/config_diff_$6-$2-$3.tgz" "$LIST"
        rm -f "$LIST"

umount /mnt/backup
Hope this will help you in creating your own script.

Last edited by Satyaveer Arya; 12-23-2011 at 12:04 PM.
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Backup only user created data thepalsrus Linux - Newbie 4 08-28-2009 01:54 PM
tar backup of an XP directory fof3 Linux - Newbie 2 03-31-2007 03:39 PM
User tar to create multiple backup files Canmetal Linux - General 3 03-24-2006 03:56 PM
dont want backup files to be created in mandrake 10.0 ranger225 Linux - Newbie 5 09-23-2004 04:36 PM
Using tar to backup a directory and subdirs n1wil Linux - General 1 08-07-2002 10:32 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:43 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration