I am using Backup and Migrate SFTP 7.x-1.0 with Backup and Migrate 7.x-3.0 and Drupal 7. Everything is fully patched/updated.

The problem is that, when I create a new destination, SFTP is not an option. Only FTP is an option.

I have installed and confirmed the "ssh2" PECL module for PHP, restarted my server, and cleared all caches.

After all of this, I still don't see SFTP as an option when I create a new destination.

Please help. I need to get his working. We currently do not have backups in place. All help is greatly appreciated.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

MrSasquatch’s picture

Does this project not do troubleshooting of issues? Is the project still maintained? I submitted my issue several days ago, and I have not seen so much as a comment. Just wondering if I should continue monitoring the issue or not. Please advise. Any help is greatly appreciated.

Leeteq’s picture

FYI - ref. this issue in the Backup_Migrate issue queue:
#622054: SSH/SFTP remote access

damienmckenna’s picture

Title: SFTP is not an option when creating a new destination » Update SFTP to be compatible with Backup Migrate v3

I suspect the module needs to be updated to the latest APIs.

rtdean93’s picture

Any update on this?

sreher’s picture

The listing of the sftp directory, also doesn't work in my installtion.

But I replace the ftp destination with the sftp for test reasons and that works.
So the code seems to be ok, but the listing of the new sftp destination is the problem.

In detail. There is a backup_migrate/includes/destinations.ftp.inc.
I replace this file with the backup_migrate_sftp/destinations.sftp.inc.
Rename the file name and the class name to backup_migrate_destination_ftp and it works.

alienseer23’s picture

Any chance of a patch???

alienseer23’s picture

StatusFileSize
new9.07 KB

I fixed it, but I don't do patches.

Here is the corrected code for the backup_migrate_sftp.module

<?php
/**
 * @sftp
 * Enable sftp backup with backup and migrate.
 *
 * Drupal Hooks
 *
 * Implements hook_backup_migrate_destination_types().
**/
function backup_migrate_sftp_backup_migrate_destination_subtypes() {
  return array(
    'sftp' => array(
      'type_name' => t('SFTP Directory'),
      'description' => t('Save the backup files to any a directory on an SFTP server.'),
      'file' => drupal_get_path('module', 'backup_migrate_sftp') . '/destinations.sftp.inc',
      'class' => 'backup_migrate_destination_sftp',
      'can_create' => TRUE,
      'remote' => TRUE,
    ),
  );
}

and I changed line 15 in /destinations.sftp.inc
from this:

class BackupMigrateDestinationSFTP extends backup_migrate_destination_remote {

to this:

class backup_migrate_destination_sftp extends backup_migrate_destination_remote {

Enjoy :)

damienmckenna’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new1.93 KB

I rolled a patch based on @alienseer23's changes. I reverted his README.txt and .info changes, and changed the info file to require B_M v3.

alienseer23’s picture

Any chance of getting this to the official repository, I'm sure that folks would appreciate that.

alienseer23’s picture

Component: User interface » Code
Status: Needs review » Patch (to be ported)

It would be great to get this patch rolled into the dev release, I've been using it for several months now with no problems, and it would be nice to stop having this show up as a necessary upgrade. Any chance of just putting it into the official repository, please?

damienmckenna’s picture

Status: Patch (to be ported) » Needs review

@alienseer23: Thanks for the review. FYI the "Patch (to be ported)" issue queue status is to indicate that an existing patch needs to be ported to a different branch of the project, it isn't for saying "this works for me".

narendrar’s picture

Patch worked for me also.

robertoperuzzo’s picture

Patch #8 doesn't work in my project: Drupal 7.43, Backup & Migrate 3.1. (Yes, of course... I need to upgrade my core. I'm going to do it asap).

When I build the project using drush makefile, I get this error:
Unable to patch backup_migrate_sftp with backup_migrate_sftp-n2292199-8.patch. [error]

I attach my patch.

cozzamara’s picture

Also I need an update version to BM v3.

cozzamara’s picture

After 2 days of searching because the #7 works only on XAMPP on Windows and not on Ubuntu 16.04 I found the solution for both system:
in destination.sftp.inc files another modify has to do.
at line 41 I had to change $stream = @fopen("ssh2.sftp://$sftp/$path/$filename", 'w');
with
$stream = @fopen("ssh2.sftp://".intval($sftp)."/$path/$filename", 'w');
For the solutions I have to say thanks to https://docs.acquia.com/article/sftp-over-ssh2-error.
So the #7's modify are all right but another one is needed.
I test it and works right.
So all call where is used the Resource value need to be changed with intval() call.

So all are Line 41, 75, 81, 103, 120, 130

cozzamara’s picture

Status: Needs review » Fixed
damienmckenna’s picture

Status: Fixed » Needs work

Please don't mark issues "fixed" until someone commits a change.

cozzamara’s picture

StatusFileSize
new8.83 KB

If someone needs the modify I made, can use the attached version that works for me.

cozzamara’s picture

Please test it

damienmckenna’s picture

Status: Needs work » Needs review
StatusFileSize
new3.08 KB

Here is @cozzamara's changes in patch format.

cozzamara’s picture

Another change in file destinations.sftp.inc needed.
At line 16 the array $supported_ops must be modify from:

 public $supported_ops = array(
    'scheduled backup',
    'manual backup',
    'restore',
    'list files',
    'configure',
    'delete',
  );

to

 public $supported_ops = array(
    'scheduled backup',
    'manual backup',
    'remote backup',
    'restore',
    'list files',
    'configure',
    'delete',
  );

So 'remote backup' needs to be added to the $supported_ops otherwise the SSH destination is not considered as Remote destination but just local destination.

cozzamara’s picture

No one did test my modify? So can someone commit a new release? Thanks.
The only negative points of this module is the compression time depends by SSH server connection speed.
A backup with ssh needs at least 10-15 minutes for my site.

cozzamara’s picture

Just another fix needed to avoid "Warning: stat(): stat failed for ssh2.sftp://8727/xxxxx/y/zzzzz20180521-21-05-2018T17-03-36.sitearchive.tar.gz.info in backup_migrate_destination_sftp->_list_files() (linea 131 di /var/www/aaaaaa/sites/all/modules/backup_migrate_sftp/destinations.sftp.inc)." when in destination folder there are other files.
On line 131 of destinations.sftp.inc replace stat function with ssh2_sftp_stat function.

cozzamara’s picture

Excuse me but ssh2_sftp_stat need 2 parameter so the right 131 line is:

$stat = ssh2_sftp_stat(intval($sftp), "ssh2.sftp://".intval($sftp)."/$path/$file");

I tested and no warnig appear in log.

Please can anyone confim?

cozzamara’s picture

Excuse me but ssh2_sftp_stat need 2 parameter so the right 131 line is:

$stat = ssh2_sftp_stat(intval($sftp), "ssh2.sftp://".intval($sftp)."/$path/$file");

I tested and no warnig appear in log.

Please can anyone confim?

cozzamara’s picture

Excuse me but ssh2_sftp_stat need 2 parameter so the right 131 line is:

$stat = ssh2_sftp_stat(intval($sftp), "ssh2.sftp://".intval($sftp)."/$path/$file");

I tested and no warnig appear in log.

Please can anyone confim?

Sorry for three post, I made a mistake

cozzamara’s picture

Another change to 131 line:

$stat = ssh2_sftp_stat($sftp, "ssh2.sftp://".intval($sftp)."/$path/$file");

because otherwise this warning appear:

Warning: ssh2_sftp_stat() expects parameter 1 to be resource, integer given in backup_migrate_destination_sftp->_list_files() (linea 131 di /var/www/mysites/sites/all/modules/backup_migrate_sftp/destinations.sftp.inc).

cozzamara’s picture

StatusFileSize
new3.85 KB

Hello to everyone, I made another modify to the code to avoid php warning in log about

fread()

and

filesize()

functions.
To solve I removed the line:

$data = fread($stream, filesize("ssh2.sftp://$sftp/$path/$file_id"));

and I added this:

$stat = ssh2_sftp_stat($sftp, "/$path/$file_id");
$filesize = $stat['size'];
$data = fread($stream, $filesize);

So I attach a new patch with all modification of this issue. I hope it is useful.

cozzamara’s picture

StatusFileSize
new3.84 KB

robertoperuzzo’s picture

StatusFileSize
new3.54 KB

Drupal: 7.82
Backup & Migrate: 3.5

I cannot apply patch #28 neither #29 using Drush makefile, so I created a new patch starting from #20. Here is the forked issue repo.