[release] sFTP backups for DirectAdmin (version: 0.1.poralix)

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
15,143
Location
GMT +7.00
Hello,

Here you can find instructions on how to add sFTP support to backup system of DirectAdmin.

Description

A set of patched scripts to allow Directadmin to

- store
- list
- download

backups over SSH using SFTP.


Author of patches

- Alex Grebenschikov, Poralix, (www.poralix.com), 2018


Version

- Version: Version: 0.1.poralix
- Last modified: Tue Jan 30 12:43:50 +07 2018
- Repository URL: https://github.com/poralix/directadmin-sftp-backups
- Report issues to URL: https://github.com/poralix/directadmin-sftp-backups/issues
- Home page: www.poralix.com


Requirements

- For Debian servers:

Code:
apt-get install sshpass

- For CentOS:

Code:
yum install sshpass


Installation

Code:
cd /usr/local/directadmin/scripts/custom/
git clone https://github.com/poralix/directadmin-sftp-backups.git
cp -f directadmin-sftp-backups/ftp_download.php ./
cp -f directadmin-sftp-backups/ftp_list.php ./
cp -f directadmin-sftp-backups/ftp_upload.php ./
chmod 700 ftp_*.php
chown diradmin:diradmin ftp_*.php


Usage

Go to directadmin Admin login -> Admin Backup/Transfer and set:


- Username: real ssh username
- Password: real ssh password or a full path to a SSH-key
- Remote Path: full path to a backup directory from a remote server
- Port: 22


The script will detect the specified port 22 and will use SFTP to connect to SSH port. If you want FTP/FTPS just change port to 21 and update other credentials (the same script can be used for FTP/FTPS/SSH/SFTP).

If you run sFTP, SSH on a different port modify the scripts and your port to the line:

Code:
SSH_PORTS="22 2200 22022";

The line exists in all 3 files:

- ftp_download.php
- ftp_list.php
- ftp_upload.php


Comments?
 
Last edited:
Hi Alex, thanks for sharing this script, really needed.

I hope staff will integrate this in the default panel software so that others can benefit.

Really appreciated ;)
 
Last edited:
Installation went well but i cant connect to my sftp server, situation

SSH port on server that send the backup : 111
SSH port on sFTP : 22 (cant change, backup provider)

Changed: SSH_PORTS="111 11100 1110111"; was not sure to edit for the last numbers but changed anyway )

Cant connect: I'm afraid this is because of the hard coded SSH port on the sFTP server, is there a work around ?
 
SSH_PORTS="" enumerates possible variants, you can have several servers with different SSH/SFTP ports. So you can add all of them space-separated.

A port added into SSH_PORTS="" should match a target SSH port on your backup server.

Thus if your backup server runs SSH/SFTP on 22 port, it OK to leave the defaults:

Code:
SSH_PORTS="22 2200 22022";

and specify 22 port in DirectAdmin when adding a backup task.

If a target server where you want to transfer backups uses 111 port you change the line to:

Code:
SSH_PORTS="22 2200 22022 111";

or simply to

Code:
SSH_PORTS="111";

and specify 111 port in DirectAdmin when adding a backup task.

I hope it helps.
 
Ok i did change everything back as it was to make a new test but no luck:

did: SSH_PORTS="22 2200 22022";

Backup server port 22
DA server ssh port is 111 (connect from here to backup)

Username: real ssh username
- Password: real ssh password or a full path to a SSH-key
- Remote Path: full path to a backup directory from a remote server
Port 111
Secure FTP no

No joy :(
EDIT there are 2 directory's who contains :

- ftp_download.php
- ftp_list.php
- ftp_upload.php

1. directadmin/scripts/custom
2. directadmin/scripts/custom/directadmin-sftp-backups

Which to alter ?
 
Last edited:
In directadmin interface when you edit/add a backup task you should specify a target port of your backup server, in your case it is 22.
 
Hi Alex, sor far so good but...

I dont see any files to restore, somehow the files inside the backup directory is not visible
checked wiith Filezilla and the files are there, is it a bug ?
 
Working fine here with ssh on a non-standard port, backup/upload and list. Haven't tried to restore yet.

Thank you for sharing this with us and all the work you do around here.

Regards,
Alex
 
@Active8,

Do you append day, time to a backup folder in DirectAdmin? If yes, you should add the same to a full path where to read backups from.

Thus, if you have a task and in a section "Select directory for backups" you append a weekday (today's /Thursday) to a Remote Path /home/admin/admin_backups/, then a remote path will be /home/admin/admin_backups/Thursday/

And whenever you want to restore or list users from a remote server you will need to adjust a Remote Path too, e.g. /home/admin/admin_backups/Thursday/


@
dugalex,

Thanks for your feedback. I'm glad you like and it's working for you.
 
Hi Alex, i think I found the problem: encryption

Backup without encryption = visible as restore file
Backup with encryption = not visible under restore files

So as long as you don't use encryptions it works but without it: only backups but files are not shown as restorable files
Can you check this ?

EDIT:
I'm not a programmer but after changing this line in ftp_list.php the encrypted files are showing ,

Code:
                cat ${DUMP} | grep -v '^sftp> ' | grep -E '^(.*.tar.gz.*)';

Maybe Alex can make a better solution :)
 
Last edited:
Thank you for your report.

Here is a fixed version:

Code:
cd /usr/local/directadmin/scripts/custom/
wget -O ftp_list.php https://raw.githubusercontent.com/poralix/directadmin-sftp-backups/master/ftp_list.php
chmod 700 ftp_list.php
chown diradmin:diradmin ftp_list.php
 
Hi Alex, did you checked it?just installed your new version of ftp_list and the .enc files are not visible again
Did my modification with ftp_list.php and it shows again
 
Yes, it shows *.enc files on my end.

You updated the file /usr/local/directadmin/scripts/custom/ftp_list.php, correct?

And what OS version you have there?
 
Hi Alex, using Centos 7 latest and did check that file, it has the newest version:

I see the change :
cat ${DUMP} | grep -v '^sftp> ' | grep -E '^(admin|reseller|user)\.(.*)\.tar(|\.gz)(|\.enc)$';

But no sign of my enc file, onlt the regular tar.gz files are showing :)

So changed that line back to :
cat ${DUMP} | grep -v '^sftp> ' | grep -E '^(.*.tar.gz.*)';

And voila all files including enc and non encrypted shows fine in the list
really weired
 
Do you create backups on admin level? Reseller? User? Give some example please of filenames.
 
Hi Alex , did with a reseller backup level
No problems with the backup then
try to list the restorable files:

with your file , nothing is there, but when i edit the ftp_list.php as i did then:
admin.tar.gz.enc

that is ok because this is an encrypted file
 
Please try again and update the file. It should support now backups created at reseller, user levels as well.
 
Hi Alex, that last modification is ok, now the encrypted files are shown

Thank you
 
y38C8N

add sFTP support to backup system of DirectAdmin

Great work! I have a couple of questions:

- Do DirectAdmin backups truncate? I have Admin Backups with your mod set to weekly. Will I receive Full Date backups until the drive is full, or is there some logic such as (only keep X backups on remote)? I see the backups are deleted locally upon transfer, but is that all?

- I understand the password limitation with special characters is not specifically a DA/Backup issue, but in the software used. Do you think this will ever get fixed? It's not a major deal considering most backup servers are secured/firewalled off.

- The form field asks for IP, but I assume it's okay to use hostname as well?

- Admin Backups are only the DirectAdmin User accounts, so that DA can restore them, correct? This is NOT a full / system backup (httpd conf, custombuild settings, /etc/rc.conf ...? To achieve both user level (for restore) and system (for ensuring special files / mods are transferred to new install) should I create a script to do a full system backup too, or is there a schedule for full system and user level?


Thanks!
 
Thanks.

Directadmin does not remove existing backups, but it can overwrite them if they exist in a target directory.

Since I most of time work in a shell I use passwords with special characters which I'm sure won't bring issues in a console. So I try and avoid a number of characters which are reserved in Linux console: `|*$ and some others...

Yes, you can use a hostname.

There is not much sense to backups auto-generated configs. What you might really need to backup is /usr/local/directadmin/data/, /usr/local/directadmin/custombuild/custom/, /usr/local/directadmin/custombuild/options.conf, /usr/local/directadmin/plugins/, etc.

In order to backups system files and configs you might use sysbk, i.e. system backup on admin level in DirectAdmin.
 
Back
Top