Bash script to archive different files and folders into a single folder which will be named using current timestamp
I use this script to back up files that are created in different locations. I feel easy to collect all the related files and folders to compress and save them as a single zip archive which is named as per the current date and time.
#!/bin/bash
# this program creates a zip archive of myFolder(containing files and folders), file1 , file2 , file3 and file4 and puts the archive in myOpDir. The name of the final zip archive will be given by the current timestamp. For eg : final_20111220_103015.zip
#create a directory for putting all the files
myFolder="/home/user/Desktop/myFolderWithContents"
myOpDir="/home/user/Desktop/myFinalDir"
file1="/home/user/Desktop/test.tcl"
file2="/home/user/Desktop/test.dump.xml"
file3="/home/user/Desktop/myDir/test.txt"
file4="/home/user/Desktop/myDir/test.txt.xml"
mkdir $myOpDir/temp
# copy the files and folder to to temp dir
cp -r $myFolder $myOpDir/temp/`
cp $file1 $myOpDir/temp/test.tcl
cp $file2 $myOpDir/temp/test.dump.xml
cp $file3 $myOpDir/temp/test.txt
cp $file4 $myOpDir/temp/test.txt.xml
#Now compress all files in a single archive
cd $myOpDir/temp/
for FILE in `ls`;do
zip -r final_`date +%Y%m%d_%H%M%S`.zip $FILE
done
cp final_`date +%Y%m%d_%H%M%S`.zip ../
cd ..
rm -r $myOpDir/temp
#!/bin/bash
# this program creates a zip archive of myFolder(containing files and folders), file1 , file2 , file3 and file4 and puts the archive in myOpDir. The name of the final zip archive will be given by the current timestamp. For eg : final_20111220_103015.zip
#create a directory for putting all the files
myFolder="/home/user/Desktop/myFolderWithContents"
myOpDir="/home/user/Desktop/myFinalDir"
file1="/home/user/Desktop/test.tcl"
file2="/home/user/Desktop/test.dump.xml"
file3="/home/user/Desktop/myDir/test.txt"
file4="/home/user/Desktop/myDir/test.txt.xml"
mkdir $myOpDir/temp
# copy the files and folder to to temp dir
cp -r $myFolder $myOpDir/temp/`
cp $file1 $myOpDir/temp/test.tcl
cp $file2 $myOpDir/temp/test.dump.xml
cp $file3 $myOpDir/temp/test.txt
cp $file4 $myOpDir/temp/test.txt.xml
#Now compress all files in a single archive
cd $myOpDir/temp/
for FILE in `ls`;do
zip -r final_`date +%Y%m%d_%H%M%S`.zip $FILE
done
cp final_`date +%Y%m%d_%H%M%S`.zip ../
cd ..
rm -r $myOpDir/temp
Comments
for i in *; do mv "$i" "Unix_$i"; done