?
Solved

File Archiving and Compression Best Practices

Posted on 2011-02-16
5
Medium Priority
?
677 Views
Last Modified: 2013-11-14
I have been given the assignment of recommending a file archiving and compression procedure. Our files are on a dedicated Linux Server running MySQL 5.5, and PHP 5.3.5.

Our files need to be archived and stored so they can be accessed when necessary, but shouldn't be accessible to those without permission (this part may be a separate question). My question is:

Is there a software to handle the file archiving that you have used and recommend?

Is it best to archive manually, or to use an automated software?

What is the best format for compressing files without data loss?

Please include a reason for your recommendation.
0
Comment
Question by:jeremyjared74
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:florjan
ID: 34907161
I preffer tar.gz. As to handle archiving I use rsync and bash script that automates it. I use rsync uncompressed daily (so it just new files get copyed) and a weekly backup.
0
 
LVL 8

Accepted Solution

by:
rationalboss earned 1100 total points
ID: 34907211
How about just using .htaccess on a directory with the following?
Deny From All

Open in new window


The directory will not be accessible via http:// but files like PHP may be able to read it using file_get_contents(), and other languages too.

Don't archive manually if you have several files. PHP has a class for zipping.
http://www.php.net/zip

To recursively zip directories, you can check this:
http://ramui.com/articles/php-zip-files-and-directory.html

ZIP is already fine unless every byte counts in your server. There are no losses in ZIP compression. Other compressions might save you more bytes like RAR and 7z but not plenty of resources are available (not as much as for ZIP). I'll suggest go with ZIP :)
0
 
LVL 4

Assisted Solution

by:florjan
florjan earned 900 total points
ID: 34907344
This is the rsync code I use on school server. Crontab runs it once a day at 5 am (if you need any help with crontab just say) Also if you want extra security you can use chattr +i so even root has to unblock it before able to edit. Save file as something.sh and modify as needed.
#!/bin/sh
## where to store backup, with trailing slash
BACKUP_DIR=/path/to/dir/
## if you want more security
#chattr -i $BACKUP_DIR
archive() {
    from="${1}"
    target="${BACKUP_DIR}${2}"
    echo "Archiving \"${from}\" \"${target}\""
    rsync --archive --cvs-exclude --one-file-system --delete --quiet \
        "${from}" "${target}"
}

## as many entries as you want to backup (if you have more than 1 folder), no trailing slash
archive "/path/to/dir1"        "."
archive "/path/to/dir2"        "."
## optional if you need anything removed (on out school server we don't want moodle sessions)
/bin/rm -Rf $BACKUP_DIR/moodledata/sessions/

## if you want to mod permissions on files, like we want read access to people in group webadmin so they can restore backup in case of a problem but no write (that's up to root)
/bin/chmod 640 -R $BACKUP_DIRdir1/
/bin/chmod 640 -R $BACKUP_DIR/dir2/
/bin/chown -R root:webadmin $BACKUP_DIR/dir1/
/bin/chown -R root:webadmin $BACKUP_DIR/dir2/
/usr/bin/find $BACKUP_DIR/dir1/ -type d -exec chmod a+x {} \;
/usr/bin/find $BACKUP_DIR/dir2/ -type d -exec chmod a+x {} \;
## if you want more security
#chattr +i $BACKUP_DIR

Open in new window

And I do not recommend backup stored to be accessible via http or https. If user is autorized he probably has access to server via ssh client. If you also need code for weekly backup and mysql backup just say.
0
 
LVL 23

Author Comment

by:jeremyjared74
ID: 34907938
Thank you for the quick response's. I will look into each suggestion and decide which fits my situation. I will leave the question open long enough to review the suggestions (and maybe get a few more suggestions). I am leaning toward rationalboss's: suggestion, but I would like to give florjan's code a shot.
Again, thanks for the quick replies.
0
 
LVL 23

Author Comment

by:jeremyjared74
ID: 34932669
Both of the experts were very helpful with their descriptive and thorough suggestions. I appreciate it very much, you saved me unknown amounts of time and headaches.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The question appears often enough, how do I transfer my data from my old server to the new server while preserving file shares, share permissions, and NTFS permisions.  Here are my tips for handling such a transfer.
Windows Server 2003 introduced persistent Volume Shadow Copies and made 2003 a must-do upgrade.  Since then, it's been a must-implement feature for all servers doing any kind of file sharing.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question