Friday, June 6, 2008

Backup files to tarred and zip file

#!bin/bash

# backs up all files in current directory modified within last 24 hours
# in a tarred and zipped file
# Replace 1 with how many day's you want to back up files

BACKUPFILE=backup-`date +"%m-%d-%Y"`
# Embeds date in backup filename

archive=${1:-$BACKUPFILE}
#If no filename specified default to backup-MM-DD-YYYY

find . -mtime -1 -type f -print0 xargs -0 tar rvf "$archive.tar"

#check bellow command
# tar cvf - $(find . -mtime -1 -type f -print) > $archive.tar
# It works But will fail to backup file names contain space
# if there is no files containing spaces it is good

# ALSO USE bellow code but it is slow and not portable
# find . -mtime -1 -type f -exec tar rvf "$archive.tar" {} \;
# use rvf option instead of cvf otherwise only one file will be archived

gzip $archive.tar && echo "Directory $pwd backed up in \"$archive.tar.gz\" File"

4 comments:

  1. There are many zip files on my computer. Inside theirs mp3 tracks,movies,softwares and etc... Once some zip files were crashed and I was very upset. But suddenly my friend called me up and recommended me - fix zip files. It resolved my issue for seconds and without payment as far as I remembered.

    ReplyDelete
  2. Thanks for sharing this news, nice that I'm here in the forum.

    ReplyDelete
  3. A great website with interesting material

    ReplyDelete