• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.

Question Automate FTP Backup settings for domains

UnS3eN

Basic Pleskian
Server operating system version
AlmaLinux 8.10
Plesk version and microupdate number
18.0.61 #5
Trying to figure out how to automate backups to FTP for each new domain. As it stands, the only way I can see is doing it for each domain manually: go to the domain, click Backup & Restore, add remote storage settings, schedule backups.

I was hoping there was a better way of automating it so it's on by default for each new domain.

I tried adding the settings to the database directly via a script, but the issue is that the password seems to be individually encrypted, so when the script runs the value doesn't actually get saved and just gets added blank.

Code:
|  324 | domain | backup_ftp_settingactive                          | true                                                           |
|  324 | domain | backup_ftp_settinghost                            | 192.168.98.70                                                  |
|  324 | domain | backup_ftp_settingdirectory                       | backups/domain.tld                                             |
|  324 | domain | backup_ftp_settinglogin                           | pleskbkp                                                       |
|  324 | domain | backup_ftp_settingpassword                        | $AES-128-CBC$encryptedpassword==                               |
|  324 | domain | backup_ftp_settingpassive_mode                    | true                                                           |
|  324 | domain | backup_ftp_settinguse_ftps                        | false                                                          |
|  324 | domain | backup_ftp_settingbackup_password                 |                                                                |

Is there a way around this or am I forever cursed to manually add settings for each new domain?
 
I am afraid there is currently no option to manage scheduled backups via command line. It's pretty much a UI/manual operation.

EDIT: see posts below
 
Last edited:
I found this topic: https://support.plesk.com/hc/en-us/...e-scheduled-backup-tasks-in-Plesk-via-CLI-API but it doesn't seem to work.

When trying to configure FTP for a subscription:
Code:
$ sudo plesk bin backup-storage --configure ftp -subscription <domain.tld> -ftp-server <LAN_IP> -ftp-path backups/<domain.tld> -ftp-passive-mode true -ftp-login <user> -ftp-password <password>
Unknown option 'userpassword': /usr/local/psa/bin/backup-storage --configure ftp -subscription <domain.tld> -ftp-server <LAN_IP> -ftp-path backups/<domain.tld> -ftp-passive-mode true -ftp-login <user> -ftp-password <userpassword>
It's trying to pass userpassword as an option rather than a value for the -ftp-password option.

Doing the same without the password produces an access error:

Code:
Unable to access the storage: Transport error: unable to list directory: Curl error: (67) Login denied: Last FTP request: PASS ***** Last FTP response: 530 Login incorrect
Make sure you have entered the correct storage credentials. You can check them independently with the command:
  curl -v --ftp-pasv -u pleskbkp 'ftp://LAN_IP/backups/domain.tld/'

So, how does one actually pass the FTP password to be stored?
 
Code:
Unable to access the storage: Transport error: unable to list directory: Curl error: (67) Login denied: Last FTP request: PASS ***** Last FTP response: 530 Login incorrect
Make sure you have entered the correct storage credentials. You can check them independently with the command:
  curl -v --ftp-pasv -u pleskbkp 'ftp://LAN_IP/backups/domain.tld/'
even after setting the FTP_PASSWORD env var.
 
With my previous post I steered you in the wrong direction. I overlooked the fact that scheduled backups can now be managed via CLI (but haven't listed on our documentation yet). Sorry about that. Good thing your where persistent and found the support article with more details :)

It should work to setup remote storage by specifying the FTP password in the FTP_PASSWORD variable. For example:
Code:
FTP_PASSWORD=<password> plesk bin backup-storage --configure ftp -subscription example.com -ftp-server <FTP HOST> -ftp-path / -ftp-passive-mode true -ftp-login <FTP USER> -ftp-password

Does it work to connect via CURL directly curl -v --ftp-pasv -u pleskbkp 'ftp://LAN_IP/backups/domain.tld/' ?
 
Does it work to connect via CURL directly curl -v --ftp-pasv -u pleskbkp 'ftp://LAN_IP/backups/domain.tld/' ?

Yes, the test cURL works fine, but it asks for the passwords explicitly when you run it.

FTP_PASSWORD=<password> plesk bin backup-storage --configure ftp ....
This doesn't return anything - no errors and no success messages - and seems to run. However, when I go in to the domain's backup manager to check the FTP settings, nothing has been added.

Also,
# plesk bin backup-storage --enable ftp
The storage 'ftp' is either not configured or not available. The acceptable storages are:

exit status 1

# plesk bin backup-storage --list-backups ftp
The storage 'ftp' is either not configured or not available. The acceptable storages are: server

exit status 1
 
Correction: the settings are added, but the Backup Manager still shows FTP inactive, so it doesn't appear in the Scheduler as an option.

Edit:
Seems like it needs to be explicitly enabled by running:
plesk bin backup-storage --enable ftp -subscription <domain.tld>
 
SOLVED (I think).
For anyone looking to automate this:
Step 1. Make sure you have the target dir set up on the FTP server - it needs to exist when the settings are validated and doesn't get created automatically

Step 2. Set up the FTP target and credentials (in my case the target is a domain dir in the 'backups' dir):
Code:
 FTP_PASSWORD=<ftpuserpassword> plesk bin backup-storage --configure ftp -subscription <domain.tld> -ftp-server <FTP_IP_OR_FQDN> -ftp-path backups/<domain.tld> -ftp-passive-mode true -ftp-login <ftpuser> -ftp-password

Step 3. Enable the backup setting - the previous step only adds the details but leaves the FTP storage inactive:
Code:
 plesk bin backup-storage --enable ftp -subscription <domain.tld>

Step 4. Configure the schedule for the FTP backups. Example code:
Code:
 plesk bin scheduled-backup --configure weekly -subscription <domain.tld> -multivolume false -exclude-mail true -full-retention 3 -full-frequency monthly -incremental true -backup-weekday sunday -backup-time 18:30 -storage ftp -keep-in-server-storage false

Step 5. Enable the schedule:
Code:
 plesk bin scheduled-backup --enable weekly -subscription <domain.tld>

Step 6. Grab a refreshing beverage of choice - you deserve it.
 
Back
Top