magento file permissions change after system backup cause 500 error

magento file permissions change after system backup cause 500 error  using -'linux,magento,file-permissions'

I'm having problems with Magento when doing a system backup. Every time I do a system backup Magento changes the file permissions and causes a 500 server error when the backup has completed and the admin screen is reloaded.

The problem is the same as this unanswered question. I am not setting 'maintenance mode' on. : Magento file permissions changing to chmod 666 after system backup

Can anyone tell me how to stop this from happening. It's a pain to have to reset the permissions every time I do a backup.

asked Oct 11, 2015 by tseetha
0 votes

1 Answer

0 votes

The problem comes about because Magento Backup sets permissions on files.

The offending piece of work is lib/Mage/Archive/Helper/File.php

In it you find a function public function open($mode = \'w+\', $chmod = 0666)

This causes issues where permissions are changed globally.

If you must use Magento's site crippling backup, then you must run a script to set the file/folder permissions back.

ssh commands (can be run as a shell script)

For Magento where PHP is running through FastCGI, suPHP, or LSAPI:

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
chmod 500 pear
chmod 500 mage #for magento 1.5+

For Magento where PHP is running as a DSO module under Apache:

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
chmod o+w var var/.htaccess app/etc
chmod 550 pear
chmod 550 mage #for magento 1.5+
chmod -R o+w media

For Magento to function, var/ and media/ may need to be recursively set to 777

From MagentoCommerce permissions settings page which also has a php script linked about halfway down that can be run to set permissions.

The other option is to dump Magento's backup system and do a roll-your-own approach with tar and mysqldump. Note: this will require plenty of free space to temporarily store the tar file till you download it unless you exclude the media/ folder and do the media folder backup in a different manner.

tar -czf magentobu.tgz --exclude="public_html/var/*" --exclude="public_html/media/catalog/product/cache/*" public_html
mysqldump -u $USER -p$PASS $DBASE > magentodb.sql

And copy the resulting files over to your offsite storage whether its your workstation, S3 bucket or vps.

Another option is to set up a system that you can rsync your Magento system to as well as pulling over a mysql dump file created once daily. Doing this, you can have a continuous, up-to-the-minute full site mirror that doesn't incur extra storage space on the server while you wait to pull the backup offsite.

answered Oct 11, 2015 by mca.agarwal