LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using TAR to create backup of files created today in data directory (http://www.linuxquestions.org/questions/linux-newbie-8/using-tar-to-create-backup-of-files-created-today-in-data-directory-920132/)

Vi_rod 12-23-2011 12:47 AM

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
done


it gives me a strange and different error everytime.. any suggestions on improving the script?

coolsg5636 12-23-2011 01:17 AM

Hello,

This script doesn't seem to be complete. Please paste the complete script and also paste the error message.

sathish_s 12-23-2011 04:04 AM

i think below will help u

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



thanks

sathish

Satyaveer Arya 12-23-2011 01:00 PM

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:

Code:

#!/bin/bash

DATA="/home /root /usr/local/httpd"
CONFIG="/etc /var/lib /var/named"
LIST="/tmp/backlist_$$.txt"

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*
else
        # 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"
fi

umount /mnt/backup

Hope this will help you in creating your own script.


All times are GMT -5. The time now is 06:30 PM.