7 use Symfony\Component\Filesystem\Filesystem;
8 use Webmozart\PathUtil\Path;
14 * Decide where our backup directory should go
16 * @param string $subdir
17 * The name of the desired subdirectory(s) under drush-backups.
18 * Usually a database name.
21 * A path to the backup directory.
24 public static function getBackupDir($subdir = null)
26 // Try to use db name as subdir if none was provided.
29 if ($sql = SqlBase::create()) {
30 $db_spec = $sql->getDbSpec();
31 $subdir = $db_spec['database'];
35 // Save the date to be used in the backup directory's path name.
36 $date = gmdate('YmdHis', $_SERVER['REQUEST_TIME']);
38 Drush::config()->home(),
46 * Prepare a backup directory.
48 * @param string $subdir
49 * A string naming the subdirectory of the backup directory.
52 * Path to the specified backup directory.
55 public static function prepareBackupDir($subdir = null)
57 $fs = new Filesystem();
58 $backup_dir = self::getBackupDir($subdir);
59 $fs->mkdir($backup_dir);
64 * Returns canonicalized absolute pathname.
66 * The difference between this and PHP's realpath() is that this will
67 * return the original path even if it doesn't exist.
70 * The path being checked.
73 * The canonicalized absolute pathname.
75 public static function realpath($path)
77 $realpath = realpath($path);
78 return $realpath ?: $path;