We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27889
    • 415 Posts
    Often hosteur disallow sql connection from an address which is not on the domain, so I had the idea to use modx url to connect to the db.
    This little script use http://curl.haxx.se/download.html"" target="_blank" rel="nofollow">curl to connect to the manager and retrieve the backup generated by MODx.
    Check the prefix table (mine is ’_modx’).
    Is it in bash for linux but it is not difficult to convert for windows, or you can download the windows version.
    You can put it in crontab to automatically retrieve the backup.
    Be carefull : if you have additionnal table which are not part of MODx default install (like jot, maxigallery (added)) these tables must be added to the query or they won’t be backed up.
    #!/bin/bash
    echo "-----------------------------------------------------------------"
    
    # your host name 
    HOST=dp-site.fr
    #the Folder where to put the file
    BACKDIR=/media/hda3/archives/
    # Your MODx manager user login and password, Dont forget to escape your chars ie:for ' ' = %20 
    USER=xxxx
    PASSWORD=xxxx
    # Name of the file
    FILENAME=$(date +%Y-%m-%d-%H-%M-%S)
    # String to append to the Name of the file
    FILEPOSTFIX='_bak.sql'
    # your modx prefix for database
    MODXPREFIXTABLE=_modx
    m=_modx
    #$MODXPREFIXTABLE
    
    
    file=$BACKDIR$FILENAME$FILEPOSTFIX
    
    echo Backup name: $file 
    echo "  Login"
    eval  "curl $HOST/manager/processors/login.processor.php -D "$BACKDIR"modxheader.txt -d \"username="$USER"&password="$PASSWORD"&submit=Connecter&rememberme=checked\""
    #curl $HOST"/manager/processors/login.processor.php -D "$BACKDIR"modxheader.txt -d username="$USER"&password="$PASSWORD"&submit=Connecter&rememberme=checked"
    echo "  Get the backup"
    curl -b modxheader.txt $HOST/manager/index.php?a=93 -d "mode=backup&droptables=on&chkselall=on&chk%5B%5D=modx_active_users&chk%5B%5D=modx_categories&chk%5B%5D=modx_document_groups&chk%5B%5D=modx_documentgroup_names&chk%5B%5D=modx_event_log&chk%5B%5D=modx_jot_content&chk%5B%5D=modx_jot_fields&chk%5B%5D=modx_jot_subscriptions&chk%5B%5D=modx_keyword_xref&chk%5B%5D=modx_manager_log&chk%5B%5D=modx_manager_users&chk%5B%5D=modx_maxigallery&chk%5B%5D=modx_member_groups&chk%5B%5D=modx_membergroup_access&chk%5B%5D=modx_membergroup_names&chk%5B%5D=modx_site_content&chk%5B%5D=modx_site_content_metatags&chk%5B%5D=modx_site_htmlsnippets&chk%5B%5D=modx_site_keywords&chk%5B%5D=modx_site_metatags&chk%5B%5D=modx_site_module_access&chk%5B%5D=modx_site_module_depobj&chk%5B%5D=modx_site_modules&chk%5B%5D=modx_site_plugin_events&chk%5B%5D=modx_site_plugins&chk%5B%5D=modx_site_snippets&chk%5B%5D=modx_site_templates&chk%5B%5D=modx_site_tmplvar_access&chk%5B%5D=modx_site_tmplvar_contentvalues&chk%5B%5D=modx_site_tmplvar_templates&chk%5B%5D=modx_site_tmplvars&chk%5B%5D=modx_system_eventnames&chk%5B%5D=modx_system_settings&chk%5B%5D=modx_user_attributes&chk%5B%5D=modx_user_messages&chk%5B%5D=modx_user_roles&chk%5B%5D=modx_user_settings&chk%5B%5D=modx_web_groups&chk%5B%5D=modx_web_user_attributes&chk%5B%5D=modx_web_user_settings&chk%5B%5D=modx_web_users&chk%5B%5D=modx_webgroup_access&chk%5B%5D=modx_webgroup_names&chk%5B%5D=geo&chk%5B%5D=geo2" >$file
    echo "  Compression"
    tar  -C $BACKDIR -cvf $FILENAME$FILEPOSTFIX.tar $FILENAME$FILEPOSTFIX 
    gzip $file.tar
    echo "  Nettoyage"
    rm -v $file 
    rm -v $BACKDIR"modxheader.txt"
    echo Backup terminé check your file:
    echo $file".tar.gz"
    echo "-----------------------------------------------------------------"
    
      MODx Sites & Prestations: http://dp-site.fr [Last MODx Site]
      MODx Repository: [HOME] [MetaTagsExtra] / Current Dev: [xFDM]