Im using magento and i want write script to automatically backup so i want store the outside the magento 2 root directory is it possible and how can i do it.

1 Answer 1


You can do outside Magento folder.

First create a plugin for Magento\Backup\Helper\Data of function getBackupsDir(). Then on afterGetBackupsDir changes the dir of backup.

Define plugin in di.xml

Define plugin at a app/code/{Vendor}/{Modulename}/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Backup\Helper\Data">
        <plugin name="change_backup_dir" type="{VendorName}\{Modulename}\Plugin\DataBackupPlugin" sortOrder="1" />

Plugin Class:

namespace {VendorName}\{Modulename}\Plugin;
class DataBackupPlugin
    public function afterGetBackupsDir(
        \Magento\Backup\Helper $subject,
        array  $result
        /* Should Use Absolulated path */
        /* Here  i have set my back directory is /var/www/ */
        return '/var/www/';



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.