Automatic User Backups

floyd

Verified User
Joined
Mar 29, 2005
Messages
6,251
Some have asked about automatic user backups that the user can set up. Here is a script using the DirectAdmin API that will do it. Its written in Perl. If the user uses 2-Step Authentication then this will not work. The user can put this in his home directory then create a cron job to call it. Set the top 4 variables.

Required perl modules:
HTTP::Request::Common
LWP::UserAgent
HTTP::Cookies

Permissions on the script should be 755

The cron command example if the script is named backup.pl:
/usr/bin/perl /home/username/scripts/backup.pl

This is just one way to do it.


Code:
#!/usr/bin/perl
$daip = "x.x.x.x";
$dausername = "username";
$dapassword = "password";
$domain = "domainname"; # Any of their domains will work to create a backup of all


use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
use HTTP::Cookies;
$ua = new LWP::UserAgent;
$ua->cookie_jar(HTTP::Cookies->new);

$url = "http://$dausername\:$dapassword\@$daip\:2222/CMD_API_SITE_BACKUP";

#print "$url\n";

my $req = POST $url,[
action => 'backup',
database_data_aware => 'yes',
email_data_aware => 'yes',
type => 'sitebackup',
domain => $domain,,
select0 => 'domain',
select1 => 'subdomain',
select2 => 'email',
select3 => 'forwarder',
select4 => 'autoresponder',
select5 => 'vacation',
select6 => 'list',
select7 => 'emailsettings',
select8 => 'ftp',
select9 => 'ftpsettings',
select10 => 'database',
select11 => 'database_data',
select12 => 'email_data'
];


@results = $ua->request($req)->as_string;
 
Back
Top