Script to Archive Files from Subdirectories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to Archive Files from Subdirectories
# 1  
Old 01-02-2013
Script to Archive Files from Subdirectories

Hello,

I have a CentOS server that contains a 'storage' directory. Within that directory, there could be any number of subfolders (all with unique names that match usernames).

Under each username folder, there are two additional folders: db and files

/STORAGE/user1/db/
/STORAGE/user1/files/
/STORAGE/user2/db/
/STORAGE/user2/files/
/STORAGE/user3/db/
/STORAGE/user3/files/
...
etc

I was hoping to get help with a script that will copy the contents of each DB folder for each user to a zip archive named with the date and time. Then I would also need a script that would allow me to extract any given zip file and put the files back in the original location:

BACKUP SCRIPT:

Capture /STORAGE/user1/db/, /STORAGE/user2/db/, /STORAGE/user3/db/ etc to one ZIP file called YYYY-MM-DD 00:00:00.zip.

RESTORE SCRIPT
Extract contents of ZIP file and restore the contents to /STORAGE/user1/db/, etc.

If there's a way to script this without having to list each username in the script that would be great as they change frequently. The two things that are constant is that they're always under the /STORAGE folder and they always have a /db and /files subfolder.

Thank you a MILLION in advance - scripting is definitely not my strong suit.
# 2  
Old 01-02-2013
If zip is not only archiver, you can pack with:
Code:
tar -cf `date`.tar /STORAGE/*/db /STORAGE/*/files

and unpack with

Code:
tar -xf filenameyouneed.tar

# 3  
Old 01-02-2013
Thank you! That will actually work perfectly. One question on the extraction - will it put the files back in the same subdirectories and replace the existing ones or do I need to specify a location to extract to?

Thank you!
# 4  
Old 01-03-2013
Code:
tar -xf filenameyouneed.tar -C /

will extract the files to their original location overwriting existing ones
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to archive logs and sftp to another archive server

Requirement: Under fuse application we have placeholders called containers; Every container has their logs under: <container1>/data/log/fuse.log <container1>/data/log/fuse.log.1 <container1>/data/log/fuse.log.XX <container2>/data/log/fuse.log... (6 Replies)
Discussion started by: Arjun Goswami
6 Replies

2. Shell Programming and Scripting

Need command/script to archive files older than

I need to find a way to archive all files older than a given date but there are some conditions that are making it difficult for me to find the correct command: Linux based system (RH5) there are multiple layers of directory depth I need to search each file should be tar'd in it's original... (1 Reply)
Discussion started by: KaosJedi
1 Replies

3. UNIX for Beginners Questions & Answers

Help with running a script on files located in subdirectories

Hello everyone, I'm am a newbie to coding so I am reaching out in hopes that I can get some help from this forum. I am trying to run the script below from a single directory, however the directory has many subfolders. In each of those subfolders is a file, uniquely named to that specific... (3 Replies)
Discussion started by: azurite
3 Replies

4. Shell Programming and Scripting

Bash script deleting my files, and editing files in subdirectories question

#!/bin/bash # name=$1 type=$2 number=1 for file in ./** do if then filenumber=00$number elif then filenumber=0$number fi tempname="$name""$filenumber"."$type" if (4 Replies)
Discussion started by: TheGreatGizmo
4 Replies

5. Shell Programming and Scripting

script assistance needed - create an archive of INI files

First and foremost - me != unix bubba. Here is the situation. We have a box with data AND settings in the same directory path. (Data files aren't in the SAME directories as settings.) I need a script that generates a tarred-up archive of only the INI files with the directory structure. We... (2 Replies)
Discussion started by: hindesite
2 Replies

6. Shell Programming and Scripting

Need script to select multiple files from archive directory based on the date range

hi all, here is the description to my problem. input parameters: $date1 & $date2 based on the range i need to select the archived files from the archived directory and moved them in to working directory. can u please help me in writing the code to select the multiple files based on the... (3 Replies)
Discussion started by: bbc17484
3 Replies

7. AIX

recursive archive directories and subdirectories

Hi everyone, Maybe this is simple question for many of you, but I get confused.:confused: How to archive a parent directory which contains some subdirectories and some files? I have searched this forum, there are some commands like tar,etc, I tried but can not be implemented in my system.... (6 Replies)
Discussion started by: wilsonSurya
6 Replies

8. Shell Programming and Scripting

Script to archive log files:Urgent Help required

I have no prior knowledge of Unix shell scripting,but my requriment demands to wrie a script that do fallowing things. 1.Delete older than one year log files 2.Moves files in to the directories as YYYYMM wise. 3.If files in $LOGDIR older than n=2 months tar and move them to $ARCHIVEDIR... (5 Replies)
Discussion started by: vamsx
5 Replies

9. Shell Programming and Scripting

Archive script old files

Hi All, Im trying to write a script to archive files based on the date the files were created. For example, if a group of files were created on 23rd August,I would have 230806.tar. I have a problem,I want the script to read a separately created file(readarchive.txt) to look for the path to... (1 Reply)
Discussion started by: kayarsenal
1 Replies

10. Shell Programming and Scripting

script to archive all the log files

is there a way to write a script and run with a cron job which archives all the *.log files into .tar.gz. :eek: (0 Replies)
Discussion started by: tintedwindow
0 Replies
Login or Register to Ask a Question