Scripting extraction and compression of files
In Cloud Hosting, the general process for extracting and compressing files through a cron job consists of the following steps:
- Creating the script File
- Uploading the aforementioned file to the site through FTP.
- Scheduling the cron job through the Cloud HostingControl Panel's Features tab (http://ensure.practicalhost.com).
IMPORTANT NOTE: Please make sure that you set up the cron job "command type" to be Perl to properly execute the shell script (.sh file). Cron jobs that run over 900 seconds (15 minutes) are automatically terminated.
Creating the Script File
To create the script file, simply open up a text editor on your local machine and copy/paste the sample code (provided in the examples below) for the operation you wish to accomplish:
Once complete, save the file with the .sh extension.
I. Compressing
Suggested Filename: compress.sh
NOTE: For these examples make sure to replace "/SOURCE/DIRECTORY/" and "/DESTINATION DIRECTORY" with the appropriate Web directories (like "/mnt/stor1-wc1-dfw1/123456/www.example.com/web/content/archives/").
Zip compression
To compress a directory to zip format add these lines to the script:
#!/bin/sh zip -9pr /DESTINATION/DIRECTORY/file.zip /SOURCE/DIRECTORY/
Where "file.zip" is the name that you assign to the zip file.
The final script should look similar to this:
Note: If you're only compressing a single file the script would be similar, but would not require the "r" in the options.
For example:
#!/bin/sh zip -9p /DESTINATION/DIRECTORY/file.zip /SOURCE/DIRECTORY/targetfile.txt
Tar.gz compression
Put this in the script to archive and compress a directory into a gzipped tar format:
#!/bin/sh tar -cvzf /DESTINATION/DIRECTORY/file.tar.gz /SOURCE/DIRECTORY/
Where "file.tar.gz" is the name that you assign to the compressed file.
The final script should look similar to this:
II. Extracting
Suggested Filename: decompress.sh
Zip extraction
Add these lines to decompress from zip format:
#!/bin/sh unzip -o /SOURCE/DIRECTORY/file.zip -d /DESTINATION/DIRECTORY/
Where "file.zip" is the name of the zip file to be uncompressed.
The final script should look similar to this:
(NOTE: the -o option will force unzip to overwrite existing files!)
Where "file.tar" is the name that you assign to the compressed file.
Tar.gz extraction
Put this in the script to extract from tar format:
#!/bin/sh tar -xvzf /SOURCE/DIRECTORY/file.tar.gz -C /DESTINATION/DIRECTORY/
Where "file.tar.gz" is the name of the compressed file.
The final script should look similar to this:
Comments
0 comments
Please sign in to leave a comment.