Compress then Delete


 
Thread Tools Search this Thread
Top Forums Web Development Compress then Delete
# 1  
Old 05-16-2011
Compress then Delete

Hi all,

Someone please help with a script that will compress a directory for backed up:

home/main/directory2Bcompressed/
home/main/directory2Bcompressed_date.zip

Then all the files in the directory are to be deleted right afterwards, emptied out for new files to come in:

home/main/directory2Bcompressed/ <--- emptied

Then the process starts all over. I am looking to have things done bi weekly. The files in the directory are images and videos.

Thanks in advance,
MrDude
# 2  
Old 05-16-2011
Standard zip has options to do most of this. See man page for zip. If you are paranoid, you can zip the files, pull a listing from the zip, compare each file bit for bit between the archive and the disk using cmp and unzip to stdout, log errors for any that are mismatched and only delete those that match. You might want to log and avoid any files that are open, using fuser to check for open()s.
# 3  
Old 05-16-2011
i don't have total control over the machine... everything is going to be done through a web interface.
# 4  
Old 05-17-2011
Well, your client script can do all these sorts of funtions using tools like wget to substitute web server actions for local ones. Are you archiving on the server, or the client?
# 5  
Old 08-29-2011
If i understand what you want you to do, you want to be able to specify a directory and then have it zipped up, but wish to initiate it remotely via a browser.

I would the php command shell_exec();
Then using the zip command, specify what you need done.
Then using the rm command to remove the initial directory.
If you need more elaborate information, don't hesitate to ask Smilie
# 6  
Old 08-29-2011
and you can use a cron job for this to run weekly

---------- Post updated at 01:35 PM ---------- Previous update was at 01:34 PM ----------

I have a script like this. if you are interested please let me know. it is done with php
# 7  
Old 09-26-2011
If you have shell access or cron can be setup to do with simple 3-4 commands

echo "Compression started"
zip home/main/directory2Bcompressed_date.zip home/main/directory2Bcompressed/
cd home/main/directory2Bcompressed/
rm -rf *
Echo "Content deleted from the folder"
echo "DONE!!"

---------- Post updated at 11:23 AM ---------- Previous update was at 11:22 AM ----------

Ahh with php i really dont know how to but you can defiantly get it done but for which you need to enabled
exec or shell_exec which is not recommended by security prospect of your server.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compress every file

Dear Experts, I am new to this forum. Thank you for moderator to allow me to join. I have a question about automatic compression using sh and crontab on an application which runs on the Suse Linux Server 11 SP4. My question is how to compress every file in a directory into its own tar... (5 Replies)
Discussion started by: Steven_2975
5 Replies

2. Shell Programming and Scripting

Script to compress and delete the older logs

Hello Guys, Can you please help me with a script which zips the older log files(1-2 weeks) and delete them? I want to run the script manually instead of setting it up in a cron job. Appreciate your help. Regards, Kris (6 Replies)
Discussion started by: kriss.gv
6 Replies

3. Shell Programming and Scripting

Compress and delete folders

Hello, can someone help me to create a short script that tar.gz all folders form a specific folder and the delete the folders themself (without deleting the tar.gz created files)? Moreover I'd like to add it on crontab and run it each day. For example: in /tmp I have: /tmp/test/test1... (7 Replies)
Discussion started by: mab80
7 Replies

4. Shell Programming and Scripting

compress folder

hi guys, i've read that i need to use tar first before gzip. just wanted to be sure if there's no way of compressing a folder with all its files like winzip in windows? using tar then gzip in unix, i will need to open 2 zip files in order to get the files unlike winzip. i'd appreciate any... (2 Replies)
Discussion started by: adshocker
2 Replies

5. UNIX for Dummies Questions & Answers

Issue: Compress in unix server and FTP to windows and open the compress file using Winzip

Hi All ! We have to compress a big data file in unix server and transfer it to windows and uncompress it using winzip in windows. I have used the utility ZIP like the below. zip -e <newfilename> df2_test_extract.dat but when I compress files greater than 4 gb using zip utility, it... (4 Replies)
Discussion started by: sakthifire
4 Replies

6. UNIX for Dummies Questions & Answers

Need help to compress

People i have files.arc i need to compress one by one...but they need to have the same date for example jan 30 1234.arc jan 30 12334.arc jan 30 rejrne.arc jan 30 e423e4.arc jan 30 afdhnfhd.arc jan 31 aresdfds.arc I need to compres the jan 30 .arc only thank you very much (1 Reply)
Discussion started by: enkei17
1 Replies

7. Shell Programming and Scripting

How to compress & delete files in ksh

Hi, I would like to know how to go about writing a script to compress & deleate old files from /var/mqm/log file system. I am a complete beginner and would love it if someone could actually give me the code for this. Thank you. (4 Replies)
Discussion started by: vkumar
4 Replies

8. UNIX for Advanced & Expert Users

tar and compress

I need to compress and tar a couple files in a directory, but I also want the original files unchanged, ie if I compress a1.cpp , then a1.cpp becomes a1.cpp.z, but what I want after running the compress utility is to have both a1.cpp as it is and a1.cpp.z and then tar a1.cpp.z to an... (4 Replies)
Discussion started by: muru
4 Replies

9. UNIX for Advanced & Expert Users

compress in linux

hi i need to use compress command in redhat8, it's not there please help regards (6 Replies)
Discussion started by: omran
6 Replies

10. UNIX for Dummies Questions & Answers

Compress in Unix

I tried Compress ; gzip and bzip . And they don't always compress files to small . Can someone tell me if there is any compress tool better than those ? thanks (1 Reply)
Discussion started by: Sasuke
1 Replies
Login or Register to Ask a Question