Drush: commands/core/archive.drush.inc Source File

  1. 7.x doxygen/html/archive_8drush_8inc_source.html
  2. master doxygen/html/archive_8drush_8inc_source.html
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * @file
5  * An early implementation of Site Archive dump/restore. See
7  */
8 
10 
11 function archive_drush_command() {
12  $items['archive-dump'] = array(
13  'description' => 'Backup your code, files, and database into a single file.',
14  'arguments' => array(
15  'sites' => 'Optional. Site specifications, delimited by commas. Typically, list subdirectory name(s) under /sites.',
16  ),
17  // Most options on sql-dump should not be shown, so just offer a subset.
19  'description' => 'Describe the archive contents.',
20  'tags' => 'Add tags to the archive manifest. Delimit multiple by commas.',
21  'destination' => 'The full path and filename in which the archive should be stored. If omitted, it will be saved to the drush-backups directory and a filename will be generated.',
22  'overwrite' => 'Do not fail if the destination file exists; overwrite it instead. Default is --no-overwrite.',
23  'generator' => 'The generator name to store in the MANIFEST file. The default is "Drush archive-dump".',
24  'generatorversion' => 'The generator version number to store in the MANIFEST file. The default is ' . Drush::getMajorVersion() . '.',
25  'pipe' => 'Only print the destination of the archive. Useful for scripts that don\'t pass --destination.',
26  'preserve-symlinks' => 'Preserve symbolic links.',
27  'no-core' => 'Exclude Drupal core, so the backup only contains the site specific stuff.',
28  'tar-options' => 'Options passed thru to the tar command.',
29  ),
30  'examples' => array(
31  'drush archive-dump default,example.com,foo.com' => 'Write an archive containing 3 sites in it.',
32  'drush archive-dump @sites' => 'Save archive containing all sites in a multi-site.',
33  'drush archive-dump default --destination=/backups/mysite.tar' => 'Save archive to custom location.',
34  'drush archive-dump --tar-options="--exclude=.git --exclude=sites/default/files"' => 'Omits any .git directories found in the tree as well as sites/default/files.',
35  'drush archive-dump --tar-options="--exclude=%files"' => 'Placeholder %files is replaced with the real path for the current site, and that path is excluded.',
36  ),
37  'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_SITE,
38  'aliases' => array('ard', 'archive-backup', 'arb'),
39  );
40  $items['archive-restore'] = array(
41  'description' => 'Expand a site archive into a Drupal web site.',
42  'arguments' => array(
43  'file' => 'The site archive file that should be expanded.',
44  'site name' => 'Optional. Which site within the archive you want to restore. Defaults to all.',
45  ),
46  'required-arguments' => 1,
47  'options' => array(
48  'destination' => 'Specify where the Drupal site should be expanded, including the docroot. Defaults to the current working directory.',
49  'db-prefix' => 'An optional table prefix to use during restore.',
50  'db-url' => array(
51  'description' => 'A Drupal 6 style database URL indicating the target for database restore. If not provided, the archived settings.php is used.',
52  'example-value' => 'mysql://root:pass@host/db',
53  ),
54  'db-su' => 'Account to use when creating the new database. Optional.',
55  'db-su-pw' => 'Password for the "db-su" account. Optional.',
56  'overwrite' => 'Allow drush to overwrite any files in the destination. Default is --no-overwrite.',
57  'tar-options' => 'Options passed thru to the tar command.',
58  ),
59  'examples' => array(
60  'drush archive-restore ./example.tar.gz' => 'Restore the files and databases for all sites in the archive.',
61  'drush archive-restore ./example.tar.gz example.com' => 'Restore the files and database for example.com site.',
62  'drush archive-restore ./example.tar.gz --destination=/var/www/example.com/docroot' => 'Restore archive to a custom location.',
63  'drush archive-restore ./example.tar.gz --db-url=mysql://root:pass@127.0.0.1/dbname' => 'Restore archive to a new database (and customize settings.php to point there.).',
64  ),
65  'bootstrap' => DRUSH_BOOTSTRAP_NONE,
66  'aliases' => array('arr'),
67  );
68  return $items;
69 }
70 
71 /**
72  * Command callback. Generate site archive file.
73  */
74 function drush_archive_dump($sites_subdirs = '@self') {
75  $include_platform = !drush_get_option('no-core', FALSE);
76  $tar = drush_get_tar_executable();
77 
78  $sites = array();
79  list($aliases, $not_found) = drush_sitealias_resolve_sitespecs(explode(',', $sites_subdirs));
80  if (!empty($not_found)) {
81  drush_log(dt("Some site subdirectories are not valid Drupal sites: @list", array("@list" => implode(', ', $not_found))), LogLevel::WARNING);
82  }
83  foreach ($aliases as $key => $alias) {
84  $sites[$key] = $alias;
85 
86  if (($db_record = sitealias_get_databases_from_record($alias))) {
87  $sites[$key]['databases'] = $db_record;
88  }
89  else {
90  $sites[$key]['databases'] = array();
91  drush_log(dt('DB definition not found for !alias', array('!alias' => $key)), LogLevel::INFO);
92  }
93  }
94 
95  // The user can specify a destination filepath or not. That filepath might
96  // end with .gz, .tgz, or something else. At the end of this command we will
97  // gzip a file, and we want it to end up with the user-specified name (if
98  // any), but gzip renames files and refuses to compress files ending with
99  // .gz and .tgz, making our lives difficult. Solution:
100  //
101  // 1. Create a unique temporary base name to which gzip WILL append .gz.
102  // 2. If no destination is provided, set $dest_dir to a backup directory and
103  // $final_destination to be the unique name in that dir.
104  // 3. If a destination is provided, set $dest_dir to that directory and
105  // $final_destination to the exact name given.
106  // 4. Set $destination, the actual working file we will build up, to the
107  // unqiue name in $dest_dir.
108  // 5. After gzip'ing $destination, rename $destination.gz to
109  // $final_destination.
110  //
111  // Sheesh.
112 
113  // Create the unique temporary name.
114  $prefix = 'none';
115  if (!empty($sites)) {
116  $first = current($sites);
117  if ( !empty($first['databases']['default']['default']['database']) ) {
118  $prefix = count($sites) > 1 ? 'multiple_sites' : str_replace('/', '-', $first['databases']['default']['default']['database']);
119  }
120  }
121  $date = gmdate('Ymd_His');
122  $temp_dest_name = "$prefix.$date.tar";
123 
124  $final_destination = drush_get_option('destination');
125  if (!$final_destination) {
126  // No destination provided.
127  $backup = drush_include_engine('version_control', 'backup');
128  // TODO: this standard Drush pattern leads to a slightly obtuse directory structure.
129  $dest_dir = $backup->prepare_backup_dir('archive-dump');
130  if (empty($dest_dir)) {
131  $dest_dir = drush_tempdir();
132  }
133  $final_destination = "$dest_dir/$temp_dest_name.gz";
134  }
135  else {
136  // Use the supplied --destination. If it is relative, resolve it
137  // relative to the directory in which drush was invoked.
138  $command_cwd = getcwd();
139  drush_op('chdir', drush_get_context('DRUSH_OLDCWD', getcwd()));
140  // This doesn't perform realpath on the basename, but that's okay. This is
141  // not path-based security. We just use it for checking for perms later.
142  drush_mkdir(dirname($final_destination));
143  $dest_dir = realpath(dirname($final_destination));
144  $final_destination = $dest_dir . '/' . basename($final_destination);
145  drush_op('chdir', $command_cwd);
146  }
147 
148  // $dest_dir is either the backup directory or specified directory. Set our
149  // working file.
150  $destination = "$dest_dir/$temp_dest_name";
151 
152  // Validate the FINAL destination. It should be a file that does not exist
153  // (unless --overwrite) in a writable directory (and a writable file if
154  // it exists). We check all this up front to avoid failing after a long
155  // dump process.
156  $overwrite = drush_get_option('overwrite');
157  $dest_dir = dirname($final_destination);
158  $dt_args = array('!file' => $final_destination, '!dir' => $dest_dir);
159  if (is_dir($final_destination)) {
160  drush_set_error('DRUSH_ARCHIVE_DEST_IS_DIR', dt('Destination !file must be a file, not a directory.', $dt_args));
161  return;
162  }
163  else if (file_exists($final_destination)) {
164  if (!$overwrite) {
165  drush_set_error('DRUSH_ARCHIVE_DEST_EXISTS', dt('Destination !file exists; specify --overwrite to overwrite.', $dt_args));
166  return;
167  }
168  else if (!is_writable($final_destination)) {
169  drush_set_error('DRUSH_ARCHIVE_DEST_FILE_NOT_WRITEABLE', dt('Destination !file is not writable.', $dt_args));
170  return;
171  }
172  }
173  else if (!is_writable($dest_dir)) {
174  drush_set_error('DRUSH_ARCHIVE_DEST_DIR_NOT_WRITEABLE', dt('Destination directory !dir is not writable.', $dt_args));
175  return;
176  }
177 
178  // Get the extra options for tar, if any
179  $tar_extra_options = drush_sitealias_evaluate_paths_in_options(drush_get_option('tar-options', ''));
180 
181  // Start adding codebase to the archive.
182  $docroot_path = realpath(drush_get_context('DRUSH_DRUPAL_ROOT'));
183  $docroot = basename($docroot_path);
184  $workdir = dirname($docroot_path);
185 
186  if ($include_platform) {
187  $dereference = (drush_get_option('preserve-symlinks', FALSE)) ? '' : '--dereference ';
188  // Convert destination path to Unix style for tar on MinGW - see http://drupal.org/node/1844224
189  if (drush_is_mingw()) {
190  $destination_orig = $destination;
191  $destination = str_replace('\\', '/', $destination);
192  $destination = preg_replace('$^([a-zA-Z]):$', '/$1', $destination);
193  }
194  // Archive Drupal core, excluding sites dir.
195  drush_shell_cd_and_exec($workdir, "$tar {$tar_extra_options} --exclude \"{$docroot}/sites\" {$dereference}-cf %s %s", $destination, $docroot);
196  // Add sites/all to the same archive.
197  drush_shell_cd_and_exec($workdir, "$tar {$tar_extra_options} {$dereference}-rf %s %s", $destination, "{$docroot}/sites/all");
198  // Add special files in sites/ to the archive. Last 2 items are new in Drupal8.
199  $files_to_add = array('sites/README.txt', 'sites/sites.php', 'sites/example.sites.php', 'sites/development.services.yml', 'sites/example.settings.local.php');
200  foreach ($files_to_add as $file_to_add) {
201  if (file_exists($file_to_add)) {
202  drush_shell_cd_and_exec($workdir, "$tar {$dereference}-rf %s %s", $destination, $docroot . '/' . $file_to_add);
203  }
204  }
205  }
206 
207  $tmp = drush_tempdir();
208  $all_dbs = array();
209  // Dump the default database for each site and add to the archive.
210  foreach ($sites as $key => $alias) {
211  if (isset($alias['databases']['default']['default'])) {
212  $db_spec = $alias['databases']['default']['default'];
213  // Use a subdirectory name matching the docroot name.
214  drush_mkdir("{$tmp}/{$docroot}");
215 
216  // Ensure uniqueness by prefixing key if needed. Remove path delimiters.
217  $dbname = str_replace(DIRECTORY_SEPARATOR, '-', $db_spec['database']);
218  $result_file = count($sites) == 1 ? "$tmp/$dbname.sql" : str_replace('@', '', "$tmp/$key-$dbname.sql");
219 
220  $all_dbs[$key] = array(
221  'file' => basename($result_file),
222  'driver' => $db_spec['driver'],
223  );
224  $sql = drush_sql_get_class($db_spec);
225  $sql->dump($result_file);
226  drush_shell_cd_and_exec($tmp, "$tar {$tar_extra_options} --dereference -rf %s %s", $destination, basename($result_file));
227  }
228  }
229 
230  // Build a manifest file AND add sites/$subdir to archive as we go.
231  $platform = array(
232  'datestamp' => time(),
233  'formatversion' => '1.0',
234  'generator' => drush_get_option('generator', 'Drush archive-dump'),
235  'generatorversion' => drush_get_option('generatorversion', Drush::getMajorVersion()),
236  'description' => drush_get_option('description', ''),
237  'tags' => drush_get_option('tags', ''),
238  'archiveformat' => ($include_platform ? 'platform' : 'site'),
239  );
240  $contents = drush_export_ini(array('Global' => $platform));
241 
242  $i=0;
243  foreach ($sites as $key => $alias) {
244  $status = drush_invoke_process($alias, 'core-status', array(), array(), array('integrate' => FALSE));
245  if (!$status || $status['error_log']) {
246  drush_log(dt('Unable to determine sites directory for !alias', array('!alias' => $key)), LogLevel::WARNING);
247  }
248 
249  // Add the site specific directory to archive.
250  if (!empty($status['object']['%paths']['%site'])) {
251  drush_shell_cd_and_exec($workdir, "$tar {$tar_extra_options} --dereference -rf %s %s", $destination, "{$docroot}/sites/" . basename($status['object']['%paths']['%site']));
252  }
253 
254  $site = array(
255  'docroot' => DRUPAL_ROOT,
256  'sitedir' => @$status['object']['%paths']['%site'],
257  'files-public' => @$status['object']['%paths']['%files'],
258  'files-private' => @$status['object']['%paths']['%private'],
259  );
260  $site["database-default-file"] = $all_dbs[$key]['file'];
261  $site["database-default-driver"] = $all_dbs[$key]['driver'];
262  // The section title is the sites subdirectory name.
263  $info[basename($site['sitedir'])] = $site;
264  $contents .= "\n" . drush_export_ini($info);
265  unset($info);
266  $i++;
267  }
268  file_put_contents("{$tmp}/MANIFEST.ini", $contents);
269 
270  // Add manifest to archive.
271  drush_shell_cd_and_exec($tmp, "$tar --dereference -rf %s %s", $destination, 'MANIFEST.ini');
272 
273  // Ensure that default/default.settings.php is in the archive. This is needed
274  // by site-install when restoring a site without any DB.
275  // NOTE: Windows tar file replace operation is broken so we have to check if file already exists.
276  // Otherwise it will corrupt the archive.
277  $res = drush_shell_cd_and_exec($workdir, "$tar -tf %s %s", $destination, $docroot . '/sites/default/default.settings.php');
278  $output = drush_shell_exec_output();
279  if (!$res || !isset($output[0]) || empty($output[0])) {
280  drush_shell_cd_and_exec($workdir, "$tar --dereference -vrf %s %s", $destination, $docroot . '/sites/default/default.settings.php');
281  }
282 
283  // Switch back to original destination in case it was modified for tar on MinGW.
284  if (!empty($destination_orig)) {
285  $destination = $destination_orig;
286  }
287 
288  // Compress the archive
289  if (!drush_shell_exec("gzip --no-name -f %s", $destination)) {
290  // Clean up the tar file
291  drush_register_file_for_deletion($destination);
292  return drush_set_error(DRUSH_APPLICATION_ERROR, dt('Failed to gzip !destination', ['!destination' => $destination]));
293  }
294 
295  // gzip appends .gz unless the name already ends in .gz, .tgz, or .taz.
296  if ("{$destination}.gz" != $final_destination) {
297  drush_move_dir("{$destination}.gz", $final_destination, $overwrite);
298  }
299 
300  drush_log(dt('Archive saved to !dest', array('!dest' => $final_destination)), LogLevel::OK);
301  return $final_destination;
302 }
303 
304 /**
305  * Command argument complete callback.
306  *
307  * @return
308  * List of site names/aliases for archival.
309  */
311  return array('values' => array_keys(_drush_sitealias_all_list()));
312 }
313 
314 /**
315  * Command callback. Restore web site(s) from a site archive file.
316  */
317 function drush_archive_restore($file, $site_id = NULL) {
318  $tmp = drush_tempdir();
319 
320  // Get the extra options for tar, if any
321  $tar_extra_options = drush_sitealias_evaluate_paths_in_options(drush_get_option('tar-options', ''));
322 
323  if (!$files = drush_tarball_extract($file, $tmp, FALSE, $tar_extra_options)) {
324  return drush_set_error('DRUSH_ARCHIVE_UNABLE_TO_EXTRACT', dt('Unable to extract site archive tarball to !tmp.', array('!tmp' => $tmp)));
325  }
326 
327  $manifest = $tmp . '/MANIFEST.ini';
328  if (file_exists($manifest)) {
329  if (!$ini = parse_ini_file($manifest, TRUE)) {
330  return drush_set_error('DRUSH_ARCHIVE_UNABLE_TO_PARSE_MANIFEST', dt('Unable to parse MANIFEST.ini in the archive.'));
331  }
332  }
333  else {
334  $ini = drush_archive_guess_manifest($tmp);
335  }
336 
337  // Backward compatibility: 'archiveformat' did not exist
338  // in older versions of archive-dump.
339  if (!isset( $ini['Global']['archiveformat'])) {
340  $ini['Global']['archiveformat'] = 'platform';
341  }
342 
343  // Grab the first site in the Manifest and move docroot to destination.
344  $ini_tmp = $ini;
345  unset($ini_tmp['Global']);
346  $first = array_shift($ini_tmp);
347  $docroot = basename($first['docroot']);
348  $destination = drush_get_option('destination', realpath('.') . "/$docroot");
349 
350  if ($ini['Global']['archiveformat'] == 'platform') {
351  // Move the whole platform in-place at once.
352  if (!drush_move_dir("$tmp/$docroot", $destination, drush_get_option('overwrite'))) {
353  return drush_set_error('DRUSH_ARCHIVE_UNABLE_TO_RESTORE_FILES', dt('Unable to restore platform to !dest', array('!dest' => $destination)));
354  }
355  }
356  else {
357  // When no platform is included we do this on a per-site basis.
358  }
359 
360  // Loop over sites and restore databases and append to settings.php.
361  foreach ($ini as $section => $site) {
362  if ($section != 'Global' && (!isset($site_id) || $section == $site_id) && !empty($site['database-default-file'])) {
363  $site_destination = $destination . '/' . $site['sitedir'];
364  // Restore site, in case not already done above.
365  if ($ini['Global']['archiveformat'] == 'site') {
366  if (!drush_move_dir("$tmp/$docroot/" . $site['sitedir'], $site_destination, drush_get_option('overwrite'))) {
367  return drush_set_error('DRUSH_ARCHIVE_UNABLE_TO_RESTORE_FILES', dt('Unable to restore site to !dest', array('!dest' => $site_destination)));
368  }
369  }
370 
371  // Restore database.
372  $sql_file = $tmp . '/' . $site['database-default-file'];
373  if ($db_url = drush_get_option('db-url')) {
374  if (empty($site_id) && count($ini) >= 3) {
375  // TODO: Use drushrc to provide multiple db-urls for multi-restore?
376  return drush_set_error('DRUSH_ARCHIVE_UNABLE_MULTI_RESTORE', dt('You must specify a site to restore when the archive contains multiple sites and a db-url is provided.'));
377  }
378  $db_spec = drush_convert_db_from_db_url($db_url);
379  }
380  else {
381  $site_specification = $destination . '#' . $section;
382  if ($return = drush_invoke_process($site_specification, 'sql-conf', array(), array('all' => TRUE), array('integrate' => FALSE, 'override-simulated' => TRUE))) {
383  $databases = $return['object'];
384  $db_spec = $databases['default']['default'];
385  }
386  else {
387  return drush_set_error('DRUSH_ARCHIVE_UNABLE_DISCOVER_DB', dt('Unable to get database details from db-url option or settings.php', array('!key' => $key)));
388  }
389  }
390  $sql = drush_sql_get_class($db_spec);
391  $sql->drop_or_create();
392  $sql->query(NULL, $sql_file);
393 
394  // Append new DB info to settings.php.
395  if ($db_url) {
396  $settingsfile = $destination . '/' . $site['sitedir'] . '/settings.php';
397  //If settings.php doesn't exist in the archive, create it from default.settings.php.
398  if (!file_exists($settingsfile)) {
399  drush_op('copy', $destination . '/sites/default/default.settings.php', $settingsfile);
400  }
401  // Need to do something here or else we can't write.
402  chmod($settingsfile, 0664);
403  file_put_contents($settingsfile, "\n// Appended by drush archive-restore command.\n", FILE_APPEND);
404  if (drush_drupal_major_version($destination) >= 7) {
405  file_put_contents($settingsfile, "\n" . '$databases = ' . var_export(drush_sitealias_convert_db_from_db_url($db_url), TRUE) . ";\n", FILE_APPEND);
406  }
407  else {
408  file_put_contents($settingsfile, "\n" . '$db_url = \'' . $db_url . "';\n", FILE_APPEND);
409  }
410  drush_log(dt('Drush appended the new database configuration at settings.php. Optionally remove the old configuration manually.'), LogLevel::OK);
411  }
412  }
413  }
414  drush_log(dt('Archive restored to !dest', array('!dest' => $destination)), LogLevel::OK);
415 
416  return $destination;
417 }
418 
419 
420 /**
421  * Command argument complete callback.
422  *
423  * @return
424  * Strong glob of files to complete on.
425  */
427  return array(
428  'files' => array(
429  'directories' => array(
430  'pattern' => '*',
431  'flags' => GLOB_ONLYDIR,
432  ),
433  'tar' => array(
434  'pattern' => '*.tar.gz',
435  ),
436  ),
437  );
438 }
439 
440 /**
441  * Try to find docroot and DB dump file in an extracted archive.
442  *
443  * @param string $path The location of the extracted archive.
444  * @return array The manifest data.
445  */
447  $db_file = drush_scan_directory($path, '/\.sql$/', array('.', '..', 'CVS'), 0, 0);
448 
449  if (file_exists($path . '/index.php')) {
450  $docroot = './';
451  }
452  else {
453  $directories = glob($path . '/*' , GLOB_ONLYDIR);
454  $docroot = reset($directories);
455  }
456 
457  $ini = array(
458  'Global' => array(
459  // Very crude detection of a platform...
460  'archiveformat' => (drush_drupal_version($docroot) ? 'platform' : 'site'),
461  ),
462  'default' => array(
463  'docroot' => $docroot,
464  'sitedir' => 'sites/default',
465  'database-default-file' => key($db_file),
466  ),
467  );
468 
469  return $ini;
470 }

File

doxygen/html/archive_8drush_8inc_source.html
View source
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Drush: commands/core/archive.drush.inc Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Drush
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.2 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_afac61274991793aa7e9133a8f4f291e.html">commands</a></li><li class="navelem"><a class="el" href="dir_5762b63965e3a68a35f77c23b4dd4668.html">core</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">archive.drush.inc</div>  </div>
</div><!--header-->
<div class="contents">
<a href="archive_8drush_8inc.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;&lt;?php</div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * @file</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> *   An early implementation of Site Archive dump/restore. See</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> *   http://groups.drupal.org/site-archive-format.</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;</div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;use <a class="code" href="classDrush_1_1Log_1_1LogLevel.html">Drush\Log\LogLevel</a>;</div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;</div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="keyword">function</span> archive_drush_command() {</div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;  $items[<span class="stringliteral">&#39;archive-dump&#39;</span>] = array(</div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;    <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Backup your code, files, and database into a single file.&#39;</span>,</div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;    <span class="stringliteral">&#39;arguments&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;      <span class="stringliteral">&#39;sites&#39;</span> =&gt; <span class="stringliteral">&#39;Optional. Site specifications, delimited by commas. Typically, list subdirectory name(s) under /sites.&#39;</span>,</div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;    ),</div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;    <span class="comment">// Most options on sql-dump should not be shown, so just offer a subset.</span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;    <span class="stringliteral">&#39;options&#39;</span> =&gt; drush_sql_get_table_selection_options() + array(</div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;      <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Describe the archive contents.&#39;</span>,</div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;      <span class="stringliteral">&#39;tags&#39;</span> =&gt; <span class="stringliteral">&#39;Add tags to the archive manifest. Delimit multiple by commas.&#39;</span>,</div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;      <span class="stringliteral">&#39;destination&#39;</span> =&gt; <span class="stringliteral">&#39;The full path and filename in which the archive should be stored. If omitted, it will be saved to the drush-backups directory and a filename will be generated.&#39;</span>,</div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;      <span class="stringliteral">&#39;overwrite&#39;</span> =&gt; <span class="stringliteral">&#39;Do not fail if the destination file exists; overwrite it instead. Default is --no-overwrite.&#39;</span>,</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;      <span class="stringliteral">&#39;generator&#39;</span> =&gt; <span class="stringliteral">&#39;The generator name to store in the MANIFEST file. The default is &quot;Drush archive-dump&quot;.&#39;</span>,</div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;      <span class="stringliteral">&#39;generatorversion&#39;</span> =&gt; <span class="stringliteral">&#39;The generator version number to store in the MANIFEST file. The default is &#39;</span> . Drush::getMajorVersion() . <span class="charliteral">&#39;.&#39;</span>,</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;      <span class="stringliteral">&#39;pipe&#39;</span> =&gt; <span class="stringliteral">&#39;Only print the destination of the archive. Useful for scripts that don\&#39;t pass --destination.&#39;</span>,</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;      <span class="stringliteral">&#39;preserve-symlinks&#39;</span> =&gt; <span class="stringliteral">&#39;Preserve symbolic links.&#39;</span>,</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;      <span class="stringliteral">&#39;no-core&#39;</span> =&gt; <span class="stringliteral">&#39;Exclude Drupal core, so the backup only contains the site specific stuff.&#39;</span>,</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;      <span class="stringliteral">&#39;tar-options&#39;</span> =&gt; <span class="stringliteral">&#39;Options passed thru to the tar command.&#39;</span>,</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;    ),</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;    <span class="stringliteral">&#39;examples&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;      <span class="stringliteral">&#39;drush archive-dump default,example.com,foo.com&#39;</span> =&gt; <span class="stringliteral">&#39;Write an archive containing 3 sites in it.&#39;</span>,</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;      <span class="stringliteral">&#39;drush archive-dump @sites&#39;</span> =&gt; <span class="stringliteral">&#39;Save archive containing all sites in a multi-site.&#39;</span>,</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;      <span class="stringliteral">&#39;drush archive-dump default --destination=/backups/mysite.tar&#39;</span> =&gt; <span class="stringliteral">&#39;Save archive to custom location.&#39;</span>,</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;      <span class="stringliteral">&#39;drush archive-dump --tar-options=&quot;--exclude=.git --exclude=sites/default/files&quot;&#39;</span> =&gt; <span class="stringliteral">&#39;Omits any .git directories found in the tree as well as sites/default/files.&#39;</span>,</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;      <span class="stringliteral">&#39;drush archive-dump --tar-options=&quot;--exclude=%files&quot;&#39;</span> =&gt; <span class="stringliteral">&#39;Placeholder %files is replaced with the real path for the current site, and that path is excluded.&#39;</span>,</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;    ),</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;    <span class="stringliteral">&#39;bootstrap&#39;</span> =&gt; DRUSH_BOOTSTRAP_DRUPAL_SITE,</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;    <span class="stringliteral">&#39;aliases&#39;</span> =&gt; array(<span class="stringliteral">&#39;ard&#39;</span>, <span class="stringliteral">&#39;archive-backup&#39;</span>, <span class="stringliteral">&#39;arb&#39;</span>),</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;  );</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;  $items[<span class="stringliteral">&#39;archive-restore&#39;</span>] = array(</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;    <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Expand a site archive into a Drupal web site.&#39;</span>,</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;    <span class="stringliteral">&#39;arguments&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;      <span class="stringliteral">&#39;file&#39;</span> =&gt; <span class="stringliteral">&#39;The site archive file that should be expanded.&#39;</span>,</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;      <span class="stringliteral">&#39;site name&#39;</span> =&gt; <span class="stringliteral">&#39;Optional. Which site within the archive you want to restore. Defaults to all.&#39;</span>,</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;    ),</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;    <span class="stringliteral">&#39;required-arguments&#39;</span> =&gt; 1,</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    <span class="stringliteral">&#39;options&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;      <span class="stringliteral">&#39;destination&#39;</span> =&gt; <span class="stringliteral">&#39;Specify where the Drupal site should be expanded, including the docroot. Defaults to the current working directory.&#39;</span>,</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;      <span class="stringliteral">&#39;db-prefix&#39;</span> =&gt; <span class="stringliteral">&#39;An optional table prefix to use during restore.&#39;</span>,</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;      <span class="stringliteral">&#39;db-url&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;        <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;A Drupal 6 style database URL indicating the target for database restore. If not provided, the archived settings.php is used.&#39;</span>,</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;        <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;mysql://root:pass@host/db&#39;</span>,</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;      ),</div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;      <span class="stringliteral">&#39;db-su&#39;</span> =&gt; <span class="stringliteral">&#39;Account to use when creating the new database. Optional.&#39;</span>,</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;      <span class="stringliteral">&#39;db-su-pw&#39;</span> =&gt; <span class="stringliteral">&#39;Password for the &quot;db-su&quot; account. Optional.&#39;</span>,</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;      <span class="stringliteral">&#39;overwrite&#39;</span> =&gt; <span class="stringliteral">&#39;Allow drush to overwrite any files in the destination. Default is --no-overwrite.&#39;</span>,</div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;      <span class="stringliteral">&#39;tar-options&#39;</span> =&gt; <span class="stringliteral">&#39;Options passed thru to the tar command.&#39;</span>,</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;    ),</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;    <span class="stringliteral">&#39;examples&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;      <span class="stringliteral">&#39;drush archive-restore ./example.tar.gz&#39;</span> =&gt; <span class="stringliteral">&#39;Restore the files and databases for all sites in the archive.&#39;</span>,</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;      <span class="stringliteral">&#39;drush archive-restore ./example.tar.gz example.com&#39;</span> =&gt; <span class="stringliteral">&#39;Restore the files and database for example.com site.&#39;</span>,</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;      <span class="stringliteral">&#39;drush archive-restore ./example.tar.gz --destination=/var/www/example.com/docroot&#39;</span> =&gt; <span class="stringliteral">&#39;Restore archive to a custom location.&#39;</span>,</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;      <span class="stringliteral">&#39;drush archive-restore ./example.tar.gz --db-url=mysql://root:pass@127.0.0.1/dbname&#39;</span> =&gt; <span class="stringliteral">&#39;Restore archive to a new database (and customize settings.php to point there.).&#39;</span>,</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;    ),</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;    <span class="stringliteral">&#39;bootstrap&#39;</span> =&gt; DRUSH_BOOTSTRAP_NONE,</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;    <span class="stringliteral">&#39;aliases&#39;</span> =&gt; array(<span class="stringliteral">&#39;arr&#39;</span>),</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;  );</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;  <span class="keywordflow">return</span> $items;</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;}</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;<span class="comment"> * Command callback. Generate site archive file.</span></div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00074"></a><span class="lineno"><a class="code" href="archive_8drush_8inc.html#aa7d70b7ae4d41f7e3339ee5713b3a38c">   74</a></span>&#160;<span class="keyword">function</span> <a class="code" href="archive_8drush_8inc.html#aa7d70b7ae4d41f7e3339ee5713b3a38c">drush_archive_dump</a>($sites_subdirs = <span class="stringliteral">&#39;@self&#39;</span>) {</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;  $include_platform = !<a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;no-core&#39;</span>, FALSE);</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;  $tar = <a class="code" href="includes_2environment_8inc.html#a68b121976df4c48d67d77c020e45814f">drush_get_tar_executable</a>();</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;  $sites = array();</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;  list($aliases, $not_found) = <a class="code" href="sitealias_8inc.html#a0dd349885b59373b8a067d7589d096e7">drush_sitealias_resolve_sitespecs</a>(explode(<span class="charliteral">&#39;,&#39;</span>, $sites_subdirs));</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;  <span class="keywordflow">if</span> (!empty($not_found)) {</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;    <a class="code" href="group__logging.html#ga47324b65808524558a488916b150dd51">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&quot;Some site subdirectories are not valid Drupal sites: @list&quot;</span>, array(<span class="stringliteral">&quot;@list&quot;</span> =&gt; implode(<span class="stringliteral">&#39;, &#39;</span>, $not_found))), LogLevel::WARNING);</div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;  }</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;  <span class="keywordflow">foreach</span> ($aliases as $key =&gt; $alias) {</div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;    $sites[$key] = $alias;</div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;</div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;    <span class="keywordflow">if</span> (($db_record = <a class="code" href="sitealias_8inc.html#a70da7111e390efcc4dab4f9ba52dbe8b">sitealias_get_databases_from_record</a>($alias))) {</div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;      $sites[$key][<span class="stringliteral">&#39;databases&#39;</span>] = $db_record;</div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;    }</div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;      $sites[$key][<span class="stringliteral">&#39;databases&#39;</span>] = array();</div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;      <a class="code" href="group__logging.html#ga47324b65808524558a488916b150dd51">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;DB definition not found for !alias&#39;</span>, array(<span class="stringliteral">&#39;!alias&#39;</span> =&gt; $key)), LogLevel::INFO);</div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;    }</div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;  }</div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;</div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;  <span class="comment">// The user can specify a destination filepath or not. That filepath might</span></div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;  <span class="comment">// end with .gz, .tgz, or something else. At the end of this command we will</span></div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;  <span class="comment">// gzip a file, and we want it to end up with the user-specified name (if</span></div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;  <span class="comment">// any), but gzip renames files and refuses to compress files ending with</span></div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;  <span class="comment">// .gz and .tgz, making our lives difficult. Solution:</span></div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;  <span class="comment">//</span></div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;  <span class="comment">// 1. Create a unique temporary base name to which gzip WILL append .gz.</span></div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;  <span class="comment">// 2. If no destination is provided, set $dest_dir to a backup directory and</span></div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;  <span class="comment">// $final_destination to be the unique name in that dir.</span></div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;  <span class="comment">// 3. If a destination is provided, set $dest_dir to that directory and</span></div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;  <span class="comment">// $final_destination to the exact name given.</span></div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;  <span class="comment">// 4. Set $destination, the actual working file we will build up, to the</span></div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;  <span class="comment">// unqiue name in $dest_dir.</span></div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;  <span class="comment">// 5. After gzip&#39;ing $destination, rename $destination.gz to</span></div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;  <span class="comment">// $final_destination.</span></div>
<div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;  <span class="comment">//</span></div>
<div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;  <span class="comment">// Sheesh.</span></div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;</div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;  <span class="comment">// Create the unique temporary name.</span></div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;  $prefix = <span class="stringliteral">&#39;none&#39;</span>;</div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;  <span class="keywordflow">if</span> (!empty($sites)) {</div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;    $first = current($sites);</div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;    <span class="keywordflow">if</span> ( !empty($first[<span class="stringliteral">&#39;databases&#39;</span>][<span class="stringliteral">&#39;default&#39;</span>][<span class="stringliteral">&#39;default&#39;</span>][<span class="stringliteral">&#39;database&#39;</span>]) ) {</div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;      $prefix = count($sites) &gt; 1 ? <span class="stringliteral">&#39;multiple_sites&#39;</span> : str_replace(<span class="charliteral">&#39;/&#39;</span>, <span class="charliteral">&#39;-&#39;</span>, $first[<span class="stringliteral">&#39;databases&#39;</span>][<span class="stringliteral">&#39;default&#39;</span>][<span class="stringliteral">&#39;default&#39;</span>][<span class="stringliteral">&#39;database&#39;</span>]);</div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;    }</div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;  }</div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;  $date = gmdate(<span class="stringliteral">&#39;Ymd_His&#39;</span>);</div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;  $temp_dest_name = <span class="stringliteral">&quot;$prefix.$date.tar&quot;</span>;</div>
<div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;</div>
<div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;  $final_destination = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;destination&#39;</span>);</div>
<div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;  <span class="keywordflow">if</span> (!$final_destination) {</div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;    <span class="comment">// No destination provided.</span></div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;    $backup = <a class="code" href="engines_8inc.html#a92390a2dd40c8ed5190be4af058813a8">drush_include_engine</a>(<span class="stringliteral">&#39;version_control&#39;</span>, <span class="stringliteral">&#39;backup&#39;</span>);</div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;    <span class="comment">// TODO: this standard Drush pattern leads to a slightly obtuse directory structure.</span></div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;    $dest_dir = $backup-&gt;prepare_backup_dir(<span class="stringliteral">&#39;archive-dump&#39;</span>);</div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;    <span class="keywordflow">if</span> (empty($dest_dir)) {</div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;      $dest_dir = <a class="code" href="group__filesystemfunctions.html#ga883d28ed54603b2d268902cec2379804">drush_tempdir</a>();</div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;    }</div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;    $final_destination = <span class="stringliteral">&quot;$dest_dir/$temp_dest_name.gz&quot;</span>;</div>
<div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;  }</div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;    <span class="comment">// Use the supplied --destination. If it is relative, resolve it</span></div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;    <span class="comment">// relative to the directory in which drush was invoked.</span></div>
<div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;    $command_cwd = getcwd();</div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;    <a class="code" href="drush_8inc.html#acebe9ed4e4825e6d33ab8dff2157b676">drush_op</a>(<span class="stringliteral">&#39;chdir&#39;</span>, <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_OLDCWD&#39;</span>, getcwd()));</div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;    <span class="comment">// This doesn&#39;t perform realpath on the basename, but that&#39;s okay. This is</span></div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;    <span class="comment">// not path-based security. We just use it for checking for perms later.</span></div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;    <a class="code" href="group__filesystemfunctions.html#ga6027285d97028ad3299d3aa262be8c2f">drush_mkdir</a>(dirname($final_destination));</div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;    $dest_dir = realpath(dirname($final_destination));</div>
<div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;    $final_destination = $dest_dir . <span class="charliteral">&#39;/&#39;</span> . basename($final_destination);</div>
<div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;    <a class="code" href="drush_8inc.html#acebe9ed4e4825e6d33ab8dff2157b676">drush_op</a>(<span class="stringliteral">&#39;chdir&#39;</span>, $command_cwd);</div>
<div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;  }</div>
<div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;</div>
<div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;  <span class="comment">// $dest_dir is either the backup directory or specified directory. Set our</span></div>
<div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;  <span class="comment">// working file.</span></div>
<div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;  $destination = <span class="stringliteral">&quot;$dest_dir/$temp_dest_name&quot;</span>;</div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;</div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;  <span class="comment">// Validate the FINAL destination. It should be a file that does not exist</span></div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;  <span class="comment">// (unless --overwrite) in a writable directory (and a writable file if</span></div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;  <span class="comment">// it exists). We check all this up front to avoid failing after a long</span></div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;  <span class="comment">// dump process.</span></div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;  $overwrite = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;overwrite&#39;</span>);</div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;  $dest_dir = dirname($final_destination);</div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;  $dt_args = array(<span class="stringliteral">&#39;!file&#39;</span> =&gt; $final_destination, <span class="stringliteral">&#39;!dir&#39;</span> =&gt; $dest_dir);</div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;  <span class="keywordflow">if</span> (is_dir($final_destination)) {</div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;    <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_ARCHIVE_DEST_IS_DIR&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Destination !file must be a file, not a directory.&#39;</span>, $dt_args));</div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;    <span class="keywordflow">return</span>;</div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;  }</div>
<div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (file_exists($final_destination)) {</div>
<div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;    <span class="keywordflow">if</span> (!$overwrite) {</div>
<div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;      <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_ARCHIVE_DEST_EXISTS&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Destination !file exists; specify --overwrite to overwrite.&#39;</span>, $dt_args));</div>
<div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;      <span class="keywordflow">return</span>;</div>
<div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;    }</div>
<div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;    <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!is_writable($final_destination)) {</div>
<div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;      <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_ARCHIVE_DEST_FILE_NOT_WRITEABLE&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Destination !file is not writable.&#39;</span>, $dt_args));</div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;      <span class="keywordflow">return</span>;</div>
<div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;    }</div>
<div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;  }</div>
<div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!is_writable($dest_dir)) {</div>
<div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;    <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_ARCHIVE_DEST_DIR_NOT_WRITEABLE&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Destination directory !dir is not writable.&#39;</span>, $dt_args));</div>
<div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;    <span class="keywordflow">return</span>;</div>
<div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;  }</div>
<div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;</div>
<div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;  <span class="comment">// Get the extra options for tar, if any</span></div>
<div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;  $tar_extra_options = <a class="code" href="sitealias_8inc.html#a48093d52b04d7e7e7798e281fb8ce920">drush_sitealias_evaluate_paths_in_options</a>(<a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;tar-options&#39;</span>, <span class="stringliteral">&#39;&#39;</span>));</div>
<div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;</div>
<div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160;  <span class="comment">// Start adding codebase to the archive.</span></div>
<div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;  $docroot_path = realpath(<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_DRUPAL_ROOT&#39;</span>));</div>
<div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;  $docroot = basename($docroot_path);</div>
<div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;  $workdir = dirname($docroot_path);</div>
<div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;</div>
<div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;  <span class="keywordflow">if</span> ($include_platform) {</div>
<div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;    $dereference = (<a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;preserve-symlinks&#39;</span>, FALSE)) ? <span class="stringliteral">&#39;&#39;</span> : <span class="stringliteral">&#39;--dereference &#39;</span>;</div>
<div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;    <span class="comment">// Convert destination path to Unix style for tar on MinGW - see http://drupal.org/node/1844224</span></div>
<div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;    <span class="keywordflow">if</span> (drush_is_mingw()) {</div>
<div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;      $destination_orig = $destination;</div>
<div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;      $destination = str_replace(<span class="charliteral">&#39;\\&#39;</span>, <span class="charliteral">&#39;/&#39;</span>, $destination);</div>
<div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;      $destination = preg_replace(<span class="stringliteral">&#39;$^([a-zA-Z]):$&#39;</span>, <span class="stringliteral">&#39;/$1&#39;</span>, $destination);</div>
<div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;    }</div>
<div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;    <span class="comment">// Archive Drupal core, excluding sites dir.</span></div>
<div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;    <a class="code" href="group__commandwrappers.html#ga59e8ee9f53442f2029080ac723ed008f">drush_shell_cd_and_exec</a>($workdir, <span class="stringliteral">&quot;$tar {$tar_extra_options} --exclude \&quot;{$docroot}/sites\&quot; {$dereference}-cf %s %s&quot;</span>, $destination, $docroot);</div>
<div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;    <span class="comment">// Add sites/all to the same archive.</span></div>
<div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;    <a class="code" href="group__commandwrappers.html#ga59e8ee9f53442f2029080ac723ed008f">drush_shell_cd_and_exec</a>($workdir, <span class="stringliteral">&quot;$tar {$tar_extra_options} {$dereference}-rf %s %s&quot;</span>, $destination, <span class="stringliteral">&quot;{$docroot}/sites/all&quot;</span>);</div>
<div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;    <span class="comment">// Add special files in sites/ to the archive. Last 2 items are new in Drupal8.</span></div>
<div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;    $files_to_add = array(<span class="stringliteral">&#39;sites/README.txt&#39;</span>, <span class="stringliteral">&#39;sites/sites.php&#39;</span>, <span class="stringliteral">&#39;sites/example.sites.php&#39;</span>, <span class="stringliteral">&#39;sites/development.services.yml&#39;</span>, <span class="stringliteral">&#39;sites/example.settings.local.php&#39;</span>);</div>
<div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;    <span class="keywordflow">foreach</span> ($files_to_add as $file_to_add) {</div>
<div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;      <span class="keywordflow">if</span> (file_exists($file_to_add)) {</div>
<div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;        <a class="code" href="group__commandwrappers.html#ga59e8ee9f53442f2029080ac723ed008f">drush_shell_cd_and_exec</a>($workdir, <span class="stringliteral">&quot;$tar {$dereference}-rf %s %s&quot;</span>, $destination, $docroot . <span class="charliteral">&#39;/&#39;</span> . $file_to_add);</div>
<div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;      }</div>
<div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;    }</div>
<div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;  }</div>
<div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;</div>
<div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160;  $tmp = <a class="code" href="group__filesystemfunctions.html#ga883d28ed54603b2d268902cec2379804">drush_tempdir</a>();</div>
<div class="line"><a name="l00208"></a><span class="lineno">  208</span>&#160;  $all_dbs = array();</div>
<div class="line"><a name="l00209"></a><span class="lineno">  209</span>&#160;  <span class="comment">// Dump the default database for each site and add to the archive.</span></div>
<div class="line"><a name="l00210"></a><span class="lineno">  210</span>&#160;  <span class="keywordflow">foreach</span> ($sites as $key =&gt; $alias) {</div>
<div class="line"><a name="l00211"></a><span class="lineno">  211</span>&#160;    <span class="keywordflow">if</span> (isset($alias[<span class="stringliteral">&#39;databases&#39;</span>][<span class="stringliteral">&#39;default&#39;</span>][<span class="stringliteral">&#39;default&#39;</span>])) {</div>
<div class="line"><a name="l00212"></a><span class="lineno">  212</span>&#160;      $db_spec = $alias[<span class="stringliteral">&#39;databases&#39;</span>][<span class="stringliteral">&#39;default&#39;</span>][<span class="stringliteral">&#39;default&#39;</span>];</div>
<div class="line"><a name="l00213"></a><span class="lineno">  213</span>&#160;      <span class="comment">// Use a subdirectory name matching the docroot name.</span></div>
<div class="line"><a name="l00214"></a><span class="lineno">  214</span>&#160;      <a class="code" href="group__filesystemfunctions.html#ga6027285d97028ad3299d3aa262be8c2f">drush_mkdir</a>(<span class="stringliteral">&quot;{$tmp}/{$docroot}&quot;</span>);</div>
<div class="line"><a name="l00215"></a><span class="lineno">  215</span>&#160;</div>
<div class="line"><a name="l00216"></a><span class="lineno">  216</span>&#160;      <span class="comment">// Ensure uniqueness by prefixing key if needed. Remove path delimiters.</span></div>
<div class="line"><a name="l00217"></a><span class="lineno">  217</span>&#160;      $dbname = str_replace(DIRECTORY_SEPARATOR, <span class="charliteral">&#39;-&#39;</span>, $db_spec[<span class="stringliteral">&#39;database&#39;</span>]);</div>
<div class="line"><a name="l00218"></a><span class="lineno">  218</span>&#160;      $result_file = count($sites) == 1 ? <span class="stringliteral">&quot;$tmp/$dbname.sql&quot;</span> : str_replace(<span class="charliteral">&#39;@&#39;</span>, <span class="stringliteral">&#39;&#39;</span>, <span class="stringliteral">&quot;$tmp/$key-$dbname.sql&quot;</span>);</div>
<div class="line"><a name="l00219"></a><span class="lineno">  219</span>&#160;</div>
<div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160;      $all_dbs[$key] = array(</div>
<div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160;        <span class="stringliteral">&#39;file&#39;</span> =&gt; basename($result_file),</div>
<div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;        <span class="stringliteral">&#39;driver&#39;</span> =&gt; $db_spec[<span class="stringliteral">&#39;driver&#39;</span>],</div>
<div class="line"><a name="l00223"></a><span class="lineno">  223</span>&#160;      );</div>
<div class="line"><a name="l00224"></a><span class="lineno">  224</span>&#160;      $sql = <a class="code" href="sql_8drush_8inc.html#a828cf565e2e7e569e41c3fbe8a8e0cf0">drush_sql_get_class</a>($db_spec);</div>
<div class="line"><a name="l00225"></a><span class="lineno">  225</span>&#160;      $sql-&gt;dump($result_file);</div>
<div class="line"><a name="l00226"></a><span class="lineno">  226</span>&#160;      <a class="code" href="group__commandwrappers.html#ga59e8ee9f53442f2029080ac723ed008f">drush_shell_cd_and_exec</a>($tmp, <span class="stringliteral">&quot;$tar {$tar_extra_options} --dereference -rf %s %s&quot;</span>, $destination, basename($result_file));</div>
<div class="line"><a name="l00227"></a><span class="lineno">  227</span>&#160;    }</div>
<div class="line"><a name="l00228"></a><span class="lineno">  228</span>&#160;  }</div>
<div class="line"><a name="l00229"></a><span class="lineno">  229</span>&#160;</div>
<div class="line"><a name="l00230"></a><span class="lineno">  230</span>&#160;  <span class="comment">// Build a manifest file AND add sites/$subdir to archive as we go.</span></div>
<div class="line"><a name="l00231"></a><span class="lineno">  231</span>&#160;  $platform = array(</div>
<div class="line"><a name="l00232"></a><span class="lineno">  232</span>&#160;    <span class="stringliteral">&#39;datestamp&#39;</span> =&gt; time(),</div>
<div class="line"><a name="l00233"></a><span class="lineno">  233</span>&#160;    <span class="stringliteral">&#39;formatversion&#39;</span> =&gt; <span class="stringliteral">&#39;1.0&#39;</span>,</div>
<div class="line"><a name="l00234"></a><span class="lineno">  234</span>&#160;    <span class="stringliteral">&#39;generator&#39;</span> =&gt; <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;generator&#39;</span>, <span class="stringliteral">&#39;Drush archive-dump&#39;</span>),</div>
<div class="line"><a name="l00235"></a><span class="lineno">  235</span>&#160;    <span class="stringliteral">&#39;generatorversion&#39;</span> =&gt; <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;generatorversion&#39;</span>, Drush::getMajorVersion()),</div>
<div class="line"><a name="l00236"></a><span class="lineno">  236</span>&#160;    <span class="stringliteral">&#39;description&#39;</span> =&gt; <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;description&#39;</span>, <span class="stringliteral">&#39;&#39;</span>),</div>
<div class="line"><a name="l00237"></a><span class="lineno">  237</span>&#160;    <span class="stringliteral">&#39;tags&#39;</span> =&gt; <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;tags&#39;</span>, <span class="stringliteral">&#39;&#39;</span>),</div>
<div class="line"><a name="l00238"></a><span class="lineno">  238</span>&#160;    <span class="stringliteral">&#39;archiveformat&#39;</span> =&gt; ($include_platform ? <span class="stringliteral">&#39;platform&#39;</span> : <span class="stringliteral">&#39;site&#39;</span>),</div>
<div class="line"><a name="l00239"></a><span class="lineno">  239</span>&#160;  );</div>
<div class="line"><a name="l00240"></a><span class="lineno">  240</span>&#160;  $contents = <a class="code" href="drush_8inc.html#adf7f9343eeb27ca1be960ebb3a948b13">drush_export_ini</a>(array(<span class="stringliteral">&#39;Global&#39;</span> =&gt; $platform));</div>
<div class="line"><a name="l00241"></a><span class="lineno">  241</span>&#160;</div>
<div class="line"><a name="l00242"></a><span class="lineno">  242</span>&#160;  $i=0;</div>
<div class="line"><a name="l00243"></a><span class="lineno">  243</span>&#160;  <span class="keywordflow">foreach</span> ($sites as $key =&gt; $alias) {</div>
<div class="line"><a name="l00244"></a><span class="lineno">  244</span>&#160;    $status = <a class="code" href="group__dispatching.html#ga125471885af052278a0874446b332cf9">drush_invoke_process</a>($alias, <span class="stringliteral">&#39;core-status&#39;</span>, array(), array(), array(<span class="stringliteral">&#39;integrate&#39;</span> =&gt; FALSE));</div>
<div class="line"><a name="l00245"></a><span class="lineno">  245</span>&#160;    <span class="keywordflow">if</span> (!$status || $status[<span class="stringliteral">&#39;error_log&#39;</span>]) {</div>
<div class="line"><a name="l00246"></a><span class="lineno">  246</span>&#160;      <a class="code" href="group__logging.html#ga47324b65808524558a488916b150dd51">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Unable to determine sites directory for !alias&#39;</span>, array(<span class="stringliteral">&#39;!alias&#39;</span> =&gt; $key)), LogLevel::WARNING);</div>
<div class="line"><a name="l00247"></a><span class="lineno">  247</span>&#160;    }</div>
<div class="line"><a name="l00248"></a><span class="lineno">  248</span>&#160;</div>
<div class="line"><a name="l00249"></a><span class="lineno">  249</span>&#160;    <span class="comment">// Add the site specific directory to archive.</span></div>
<div class="line"><a name="l00250"></a><span class="lineno">  250</span>&#160;    <span class="keywordflow">if</span> (!empty($status[<span class="stringliteral">&#39;object&#39;</span>][<span class="stringliteral">&#39;%paths&#39;</span>][<span class="stringliteral">&#39;%site&#39;</span>])) {</div>
<div class="line"><a name="l00251"></a><span class="lineno">  251</span>&#160;      <a class="code" href="group__commandwrappers.html#ga59e8ee9f53442f2029080ac723ed008f">drush_shell_cd_and_exec</a>($workdir, <span class="stringliteral">&quot;$tar {$tar_extra_options} --dereference -rf %s %s&quot;</span>, $destination,  <span class="stringliteral">&quot;{$docroot}/sites/&quot;</span> . basename($status[<span class="stringliteral">&#39;object&#39;</span>][<span class="stringliteral">&#39;%paths&#39;</span>][<span class="stringliteral">&#39;%site&#39;</span>]));</div>
<div class="line"><a name="l00252"></a><span class="lineno">  252</span>&#160;    }</div>
<div class="line"><a name="l00253"></a><span class="lineno">  253</span>&#160;</div>
<div class="line"><a name="l00254"></a><span class="lineno">  254</span>&#160;    $site = array(</div>
<div class="line"><a name="l00255"></a><span class="lineno">  255</span>&#160;      <span class="stringliteral">&#39;docroot&#39;</span> =&gt; DRUPAL_ROOT,</div>
<div class="line"><a name="l00256"></a><span class="lineno">  256</span>&#160;      <span class="stringliteral">&#39;sitedir&#39;</span> =&gt; @$status[<span class="stringliteral">&#39;object&#39;</span>][<span class="stringliteral">&#39;%paths&#39;</span>][<span class="stringliteral">&#39;%site&#39;</span>],</div>
<div class="line"><a name="l00257"></a><span class="lineno">  257</span>&#160;      <span class="stringliteral">&#39;files-public&#39;</span> =&gt; @$status[<span class="stringliteral">&#39;object&#39;</span>][<span class="stringliteral">&#39;%paths&#39;</span>][<span class="stringliteral">&#39;%files&#39;</span>],</div>
<div class="line"><a name="l00258"></a><span class="lineno">  258</span>&#160;      <span class="stringliteral">&#39;files-private&#39;</span> =&gt; @$status[<span class="stringliteral">&#39;object&#39;</span>][<span class="stringliteral">&#39;%paths&#39;</span>][<span class="stringliteral">&#39;%private&#39;</span>],</div>
<div class="line"><a name="l00259"></a><span class="lineno">  259</span>&#160;    );</div>
<div class="line"><a name="l00260"></a><span class="lineno">  260</span>&#160;    $site[<span class="stringliteral">&quot;database-default-file&quot;</span>] = $all_dbs[$key][<span class="stringliteral">&#39;file&#39;</span>];</div>
<div class="line"><a name="l00261"></a><span class="lineno">  261</span>&#160;    $site[<span class="stringliteral">&quot;database-default-driver&quot;</span>] = $all_dbs[$key][<span class="stringliteral">&#39;driver&#39;</span>];</div>
<div class="line"><a name="l00262"></a><span class="lineno">  262</span>&#160;    <span class="comment">// The section title is the sites subdirectory name.</span></div>
<div class="line"><a name="l00263"></a><span class="lineno">  263</span>&#160;    $info[basename($site[<span class="stringliteral">&#39;sitedir&#39;</span>])] = $site;</div>
<div class="line"><a name="l00264"></a><span class="lineno">  264</span>&#160;    $contents .= <span class="stringliteral">&quot;\n&quot;</span> . <a class="code" href="drush_8inc.html#adf7f9343eeb27ca1be960ebb3a948b13">drush_export_ini</a>($info);</div>
<div class="line"><a name="l00265"></a><span class="lineno">  265</span>&#160;    unset($info);</div>
<div class="line"><a name="l00266"></a><span class="lineno">  266</span>&#160;    $i++;</div>
<div class="line"><a name="l00267"></a><span class="lineno">  267</span>&#160;  }</div>
<div class="line"><a name="l00268"></a><span class="lineno">  268</span>&#160;  file_put_contents(<span class="stringliteral">&quot;{$tmp}/MANIFEST.ini&quot;</span>, $contents);</div>
<div class="line"><a name="l00269"></a><span class="lineno">  269</span>&#160;</div>
<div class="line"><a name="l00270"></a><span class="lineno">  270</span>&#160;  <span class="comment">// Add manifest to archive.</span></div>
<div class="line"><a name="l00271"></a><span class="lineno">  271</span>&#160;  <a class="code" href="group__commandwrappers.html#ga59e8ee9f53442f2029080ac723ed008f">drush_shell_cd_and_exec</a>($tmp, <span class="stringliteral">&quot;$tar --dereference -rf %s %s&quot;</span>, $destination, <span class="stringliteral">&#39;MANIFEST.ini&#39;</span>);</div>
<div class="line"><a name="l00272"></a><span class="lineno">  272</span>&#160;</div>
<div class="line"><a name="l00273"></a><span class="lineno">  273</span>&#160;  <span class="comment">// Ensure that default/default.settings.php is in the archive. This is needed</span></div>
<div class="line"><a name="l00274"></a><span class="lineno">  274</span>&#160;  <span class="comment">// by site-install when restoring a site without any DB.</span></div>
<div class="line"><a name="l00275"></a><span class="lineno">  275</span>&#160;  <span class="comment">// NOTE: Windows tar file replace operation is broken so we have to check if file already exists.</span></div>
<div class="line"><a name="l00276"></a><span class="lineno">  276</span>&#160;  <span class="comment">// Otherwise it will corrupt the archive.</span></div>
<div class="line"><a name="l00277"></a><span class="lineno">  277</span>&#160;  $res = <a class="code" href="group__commandwrappers.html#ga59e8ee9f53442f2029080ac723ed008f">drush_shell_cd_and_exec</a>($workdir, <span class="stringliteral">&quot;$tar -tf %s %s&quot;</span>, $destination, $docroot . <span class="stringliteral">&#39;/sites/default/default.settings.php&#39;</span>);</div>
<div class="line"><a name="l00278"></a><span class="lineno">  278</span>&#160;  $output = <a class="code" href="group__commandwrappers.html#gadba8c59ba260dd39f615bc22ca78e1af">drush_shell_exec_output</a>();</div>
<div class="line"><a name="l00279"></a><span class="lineno">  279</span>&#160;  <span class="keywordflow">if</span> (!$res || !isset($output[0]) || empty($output[0])) {</div>
<div class="line"><a name="l00280"></a><span class="lineno">  280</span>&#160;    <a class="code" href="group__commandwrappers.html#ga59e8ee9f53442f2029080ac723ed008f">drush_shell_cd_and_exec</a>($workdir, <span class="stringliteral">&quot;$tar --dereference -vrf %s %s&quot;</span>, $destination, $docroot . <span class="stringliteral">&#39;/sites/default/default.settings.php&#39;</span>);</div>
<div class="line"><a name="l00281"></a><span class="lineno">  281</span>&#160;  }</div>
<div class="line"><a name="l00282"></a><span class="lineno">  282</span>&#160;</div>
<div class="line"><a name="l00283"></a><span class="lineno">  283</span>&#160;  <span class="comment">// Switch back to original destination in case it was modified for tar on MinGW.</span></div>
<div class="line"><a name="l00284"></a><span class="lineno">  284</span>&#160;  <span class="keywordflow">if</span> (!empty($destination_orig)) {</div>
<div class="line"><a name="l00285"></a><span class="lineno">  285</span>&#160;    $destination = $destination_orig;</div>
<div class="line"><a name="l00286"></a><span class="lineno">  286</span>&#160;  }</div>
<div class="line"><a name="l00287"></a><span class="lineno">  287</span>&#160;</div>
<div class="line"><a name="l00288"></a><span class="lineno">  288</span>&#160;  <span class="comment">// Compress the archive</span></div>
<div class="line"><a name="l00289"></a><span class="lineno">  289</span>&#160;  <span class="keywordflow">if</span> (!<a class="code" href="group__commandwrappers.html#gafd358ceac1286dbdd141ff2b8eb7d556">drush_shell_exec</a>(<span class="stringliteral">&quot;gzip --no-name -f %s&quot;</span>, $destination)) {</div>
<div class="line"><a name="l00290"></a><span class="lineno">  290</span>&#160;    <span class="comment">// Clean up the tar file</span></div>
<div class="line"><a name="l00291"></a><span class="lineno">  291</span>&#160;    <a class="code" href="group__filesystemfunctions.html#ga7557e035207db8d2dbe475e6a52c579c">drush_register_file_for_deletion</a>($destination);</div>
<div class="line"><a name="l00292"></a><span class="lineno">  292</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<a class="code" href="drush_8inc.html#ad2cac2311a09943e8f911c2d13167c4a">DRUSH_APPLICATION_ERROR</a>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Failed to gzip !destination&#39;</span>, [<span class="stringliteral">&#39;!destination&#39;</span> =&gt; $destination]));</div>
<div class="line"><a name="l00293"></a><span class="lineno">  293</span>&#160;  }</div>
<div class="line"><a name="l00294"></a><span class="lineno">  294</span>&#160;</div>
<div class="line"><a name="l00295"></a><span class="lineno">  295</span>&#160;  <span class="comment">// gzip appends .gz unless the name already ends in .gz, .tgz, or .taz.</span></div>
<div class="line"><a name="l00296"></a><span class="lineno">  296</span>&#160;  <span class="keywordflow">if</span> (<span class="stringliteral">&quot;{$destination}.gz&quot;</span> != $final_destination) {</div>
<div class="line"><a name="l00297"></a><span class="lineno">  297</span>&#160;    <a class="code" href="group__filesystemfunctions.html#gaac7379e8cfa2163a874542fc021bf521">drush_move_dir</a>(<span class="stringliteral">&quot;{$destination}.gz&quot;</span>, $final_destination, $overwrite);</div>
<div class="line"><a name="l00298"></a><span class="lineno">  298</span>&#160;  }</div>
<div class="line"><a name="l00299"></a><span class="lineno">  299</span>&#160;</div>
<div class="line"><a name="l00300"></a><span class="lineno">  300</span>&#160;  <a class="code" href="group__logging.html#ga47324b65808524558a488916b150dd51">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Archive saved to !dest&#39;</span>, array(<span class="stringliteral">&#39;!dest&#39;</span> =&gt; $final_destination)), LogLevel::OK);</div>
<div class="line"><a name="l00301"></a><span class="lineno">  301</span>&#160;  <span class="keywordflow">return</span> $final_destination;</div>
<div class="line"><a name="l00302"></a><span class="lineno">  302</span>&#160;}</div>
<div class="line"><a name="l00303"></a><span class="lineno">  303</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00304"></a><span class="lineno">  304</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00305"></a><span class="lineno">  305</span>&#160;<span class="comment"> * Command argument complete callback.</span></div>
<div class="line"><a name="l00306"></a><span class="lineno">  306</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00307"></a><span class="lineno">  307</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l00308"></a><span class="lineno">  308</span>&#160;<span class="comment"> *   List of site names/aliases for archival.</span></div>
<div class="line"><a name="l00309"></a><span class="lineno">  309</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00310"></a><span class="lineno"><a class="code" href="archive_8drush_8inc.html#a49945bfa5c147d67734c75e001faeeb8">  310</a></span>&#160;<span class="keyword">function</span> <a class="code" href="archive_8drush_8inc.html#a49945bfa5c147d67734c75e001faeeb8">archive_archive_dump_complete</a>() {</div>
<div class="line"><a name="l00311"></a><span class="lineno">  311</span>&#160;  <span class="keywordflow">return</span> array(<span class="stringliteral">&#39;values&#39;</span> =&gt; array_keys(<a class="code" href="sitealias_8drush_8inc.html#ab84f25812ecd477686e6fa349503ed8d">_drush_sitealias_all_list</a>()));</div>
<div class="line"><a name="l00312"></a><span class="lineno">  312</span>&#160;}</div>
<div class="line"><a name="l00313"></a><span class="lineno">  313</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00314"></a><span class="lineno">  314</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00315"></a><span class="lineno">  315</span>&#160;<span class="comment"> * Command callback. Restore web site(s) from a site archive file.</span></div>
<div class="line"><a name="l00316"></a><span class="lineno">  316</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00317"></a><span class="lineno"><a class="code" href="archive_8drush_8inc.html#a3d1644997af6a5792dda2213cae3f4cc">  317</a></span>&#160;<span class="keyword">function</span> <a class="code" href="archive_8drush_8inc.html#a3d1644997af6a5792dda2213cae3f4cc">drush_archive_restore</a>($file, $site_id = NULL) {</div>
<div class="line"><a name="l00318"></a><span class="lineno">  318</span>&#160;  $tmp = <a class="code" href="group__filesystemfunctions.html#ga883d28ed54603b2d268902cec2379804">drush_tempdir</a>();</div>
<div class="line"><a name="l00319"></a><span class="lineno">  319</span>&#160;</div>
<div class="line"><a name="l00320"></a><span class="lineno">  320</span>&#160;  <span class="comment">// Get the extra options for tar, if any</span></div>
<div class="line"><a name="l00321"></a><span class="lineno">  321</span>&#160;  $tar_extra_options = <a class="code" href="sitealias_8inc.html#a48093d52b04d7e7e7798e281fb8ce920">drush_sitealias_evaluate_paths_in_options</a>(<a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;tar-options&#39;</span>, <span class="stringliteral">&#39;&#39;</span>));</div>
<div class="line"><a name="l00322"></a><span class="lineno">  322</span>&#160;</div>
<div class="line"><a name="l00323"></a><span class="lineno">  323</span>&#160;  <span class="keywordflow">if</span> (!$files = <a class="code" href="drush_8inc.html#ad8f8c8d5b65e0d9a863173da63ef78ee">drush_tarball_extract</a>($file, $tmp, FALSE, $tar_extra_options)) {</div>
<div class="line"><a name="l00324"></a><span class="lineno">  324</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_ARCHIVE_UNABLE_TO_EXTRACT&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Unable to extract site archive tarball to !tmp.&#39;</span>, array(<span class="stringliteral">&#39;!tmp&#39;</span> =&gt; $tmp)));</div>
<div class="line"><a name="l00325"></a><span class="lineno">  325</span>&#160;  }</div>
<div class="line"><a name="l00326"></a><span class="lineno">  326</span>&#160;</div>
<div class="line"><a name="l00327"></a><span class="lineno">  327</span>&#160;  $manifest = $tmp . <span class="stringliteral">&#39;/MANIFEST.ini&#39;</span>;</div>
<div class="line"><a name="l00328"></a><span class="lineno">  328</span>&#160;  <span class="keywordflow">if</span> (file_exists($manifest)) {</div>
<div class="line"><a name="l00329"></a><span class="lineno">  329</span>&#160;    <span class="keywordflow">if</span> (!$ini = parse_ini_file($manifest, TRUE)) {</div>
<div class="line"><a name="l00330"></a><span class="lineno">  330</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_ARCHIVE_UNABLE_TO_PARSE_MANIFEST&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Unable to parse MANIFEST.ini in the archive.&#39;</span>));</div>
<div class="line"><a name="l00331"></a><span class="lineno">  331</span>&#160;    }</div>
<div class="line"><a name="l00332"></a><span class="lineno">  332</span>&#160;  }</div>
<div class="line"><a name="l00333"></a><span class="lineno">  333</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00334"></a><span class="lineno">  334</span>&#160;    $ini = <a class="code" href="archive_8drush_8inc.html#a51085ff955b6905e494c7da6cd84e028">drush_archive_guess_manifest</a>($tmp);</div>
<div class="line"><a name="l00335"></a><span class="lineno">  335</span>&#160;  }</div>
<div class="line"><a name="l00336"></a><span class="lineno">  336</span>&#160;</div>
<div class="line"><a name="l00337"></a><span class="lineno">  337</span>&#160;  <span class="comment">// Backward compatibility: &#39;archiveformat&#39; did not exist</span></div>
<div class="line"><a name="l00338"></a><span class="lineno">  338</span>&#160;  <span class="comment">// in older versions of archive-dump.</span></div>
<div class="line"><a name="l00339"></a><span class="lineno">  339</span>&#160;  <span class="keywordflow">if</span> (!isset( $ini[<span class="stringliteral">&#39;Global&#39;</span>][<span class="stringliteral">&#39;archiveformat&#39;</span>])) {</div>
<div class="line"><a name="l00340"></a><span class="lineno">  340</span>&#160;    $ini[<span class="stringliteral">&#39;Global&#39;</span>][<span class="stringliteral">&#39;archiveformat&#39;</span>] = <span class="stringliteral">&#39;platform&#39;</span>;</div>
<div class="line"><a name="l00341"></a><span class="lineno">  341</span>&#160;  }</div>
<div class="line"><a name="l00342"></a><span class="lineno">  342</span>&#160;</div>
<div class="line"><a name="l00343"></a><span class="lineno">  343</span>&#160;  <span class="comment">// Grab the first site in the Manifest and move docroot to destination.</span></div>
<div class="line"><a name="l00344"></a><span class="lineno">  344</span>&#160;  $ini_tmp = $ini;</div>
<div class="line"><a name="l00345"></a><span class="lineno">  345</span>&#160;  unset($ini_tmp[<span class="stringliteral">&#39;Global&#39;</span>]);</div>
<div class="line"><a name="l00346"></a><span class="lineno">  346</span>&#160;  $first = array_shift($ini_tmp);</div>
<div class="line"><a name="l00347"></a><span class="lineno">  347</span>&#160;  $docroot = basename($first[<span class="stringliteral">&#39;docroot&#39;</span>]);</div>
<div class="line"><a name="l00348"></a><span class="lineno">  348</span>&#160;  $destination = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;destination&#39;</span>, realpath(<span class="charliteral">&#39;.&#39;</span>) . <span class="stringliteral">&quot;/$docroot&quot;</span>);</div>
<div class="line"><a name="l00349"></a><span class="lineno">  349</span>&#160;</div>
<div class="line"><a name="l00350"></a><span class="lineno">  350</span>&#160;  <span class="keywordflow">if</span> ($ini[<span class="stringliteral">&#39;Global&#39;</span>][<span class="stringliteral">&#39;archiveformat&#39;</span>] == <span class="stringliteral">&#39;platform&#39;</span>) {</div>
<div class="line"><a name="l00351"></a><span class="lineno">  351</span>&#160;    <span class="comment">// Move the whole platform in-place at once.</span></div>
<div class="line"><a name="l00352"></a><span class="lineno">  352</span>&#160;    <span class="keywordflow">if</span> (!<a class="code" href="group__filesystemfunctions.html#gaac7379e8cfa2163a874542fc021bf521">drush_move_dir</a>(<span class="stringliteral">&quot;$tmp/$docroot&quot;</span>, $destination, <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;overwrite&#39;</span>))) {</div>
<div class="line"><a name="l00353"></a><span class="lineno">  353</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_ARCHIVE_UNABLE_TO_RESTORE_FILES&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Unable to restore platform to !dest&#39;</span>, array(<span class="stringliteral">&#39;!dest&#39;</span> =&gt; $destination)));</div>
<div class="line"><a name="l00354"></a><span class="lineno">  354</span>&#160;    }</div>
<div class="line"><a name="l00355"></a><span class="lineno">  355</span>&#160;  }</div>
<div class="line"><a name="l00356"></a><span class="lineno">  356</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00357"></a><span class="lineno">  357</span>&#160;    <span class="comment">// When no platform is included we do this on a per-site basis.</span></div>
<div class="line"><a name="l00358"></a><span class="lineno">  358</span>&#160;  }</div>
<div class="line"><a name="l00359"></a><span class="lineno">  359</span>&#160;</div>
<div class="line"><a name="l00360"></a><span class="lineno">  360</span>&#160;  <span class="comment">// Loop over sites and restore databases and append to settings.php.</span></div>
<div class="line"><a name="l00361"></a><span class="lineno">  361</span>&#160;  <span class="keywordflow">foreach</span> ($ini as $section =&gt; $site) {</div>
<div class="line"><a name="l00362"></a><span class="lineno">  362</span>&#160;    <span class="keywordflow">if</span> ($section != <span class="stringliteral">&#39;Global&#39;</span> &amp;&amp; (!isset($site_id) || $section == $site_id) &amp;&amp; !empty($site[<span class="stringliteral">&#39;database-default-file&#39;</span>])) {</div>
<div class="line"><a name="l00363"></a><span class="lineno">  363</span>&#160;      $site_destination = $destination . <span class="charliteral">&#39;/&#39;</span> . $site[<span class="stringliteral">&#39;sitedir&#39;</span>];</div>
<div class="line"><a name="l00364"></a><span class="lineno">  364</span>&#160;      <span class="comment">// Restore site, in case not already done above.</span></div>
<div class="line"><a name="l00365"></a><span class="lineno">  365</span>&#160;      <span class="keywordflow">if</span> ($ini[<span class="stringliteral">&#39;Global&#39;</span>][<span class="stringliteral">&#39;archiveformat&#39;</span>] == <span class="stringliteral">&#39;site&#39;</span>) {</div>
<div class="line"><a name="l00366"></a><span class="lineno">  366</span>&#160;        <span class="keywordflow">if</span> (!<a class="code" href="group__filesystemfunctions.html#gaac7379e8cfa2163a874542fc021bf521">drush_move_dir</a>(<span class="stringliteral">&quot;$tmp/$docroot/&quot;</span> . $site[<span class="stringliteral">&#39;sitedir&#39;</span>], $site_destination, <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;overwrite&#39;</span>))) {</div>
<div class="line"><a name="l00367"></a><span class="lineno">  367</span>&#160;          <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_ARCHIVE_UNABLE_TO_RESTORE_FILES&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Unable to restore site to !dest&#39;</span>, array(<span class="stringliteral">&#39;!dest&#39;</span> =&gt; $site_destination)));</div>
<div class="line"><a name="l00368"></a><span class="lineno">  368</span>&#160;        }</div>
<div class="line"><a name="l00369"></a><span class="lineno">  369</span>&#160;      }</div>
<div class="line"><a name="l00370"></a><span class="lineno">  370</span>&#160;</div>
<div class="line"><a name="l00371"></a><span class="lineno">  371</span>&#160;      <span class="comment">// Restore database.</span></div>
<div class="line"><a name="l00372"></a><span class="lineno">  372</span>&#160;      $sql_file = $tmp . <span class="charliteral">&#39;/&#39;</span> . $site[<span class="stringliteral">&#39;database-default-file&#39;</span>];</div>
<div class="line"><a name="l00373"></a><span class="lineno">  373</span>&#160;      <span class="keywordflow">if</span> ($db_url = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;db-url&#39;</span>)) {</div>
<div class="line"><a name="l00374"></a><span class="lineno">  374</span>&#160;        <span class="keywordflow">if</span> (empty($site_id) &amp;&amp; count($ini) &gt;= 3) {</div>
<div class="line"><a name="l00375"></a><span class="lineno">  375</span>&#160;          <span class="comment">// TODO: Use drushrc to provide multiple db-urls for multi-restore?</span></div>
<div class="line"><a name="l00376"></a><span class="lineno">  376</span>&#160;          <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_ARCHIVE_UNABLE_MULTI_RESTORE&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;You must specify a site to restore when the archive contains multiple sites and a db-url is provided.&#39;</span>));</div>
<div class="line"><a name="l00377"></a><span class="lineno">  377</span>&#160;        }</div>
<div class="line"><a name="l00378"></a><span class="lineno">  378</span>&#160;        $db_spec = <a class="code" href="sitealias_8inc.html#a3e5b4e0099b3cf7ad4ec47fac20e4e54">drush_convert_db_from_db_url</a>($db_url);</div>
<div class="line"><a name="l00379"></a><span class="lineno">  379</span>&#160;      }</div>
<div class="line"><a name="l00380"></a><span class="lineno">  380</span>&#160;      <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00381"></a><span class="lineno">  381</span>&#160;        $site_specification = $destination . <span class="charliteral">&#39;#&#39;</span> . $section;</div>
<div class="line"><a name="l00382"></a><span class="lineno">  382</span>&#160;        <span class="keywordflow">if</span> ($return = <a class="code" href="group__dispatching.html#ga125471885af052278a0874446b332cf9">drush_invoke_process</a>($site_specification, <span class="stringliteral">&#39;sql-conf&#39;</span>, array(), array(<span class="stringliteral">&#39;all&#39;</span> =&gt; TRUE), array(<span class="stringliteral">&#39;integrate&#39;</span> =&gt; FALSE, <span class="stringliteral">&#39;override-simulated&#39;</span> =&gt; TRUE))) {</div>
<div class="line"><a name="l00383"></a><span class="lineno">  383</span>&#160;          $databases = $return[<span class="stringliteral">&#39;object&#39;</span>];</div>
<div class="line"><a name="l00384"></a><span class="lineno">  384</span>&#160;          $db_spec = $databases[<span class="stringliteral">&#39;default&#39;</span>][<span class="stringliteral">&#39;default&#39;</span>];</div>
<div class="line"><a name="l00385"></a><span class="lineno">  385</span>&#160;        }</div>
<div class="line"><a name="l00386"></a><span class="lineno">  386</span>&#160;        <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00387"></a><span class="lineno">  387</span>&#160;          <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_ARCHIVE_UNABLE_DISCOVER_DB&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Unable to get database details from db-url option or settings.php&#39;</span>, array(<span class="stringliteral">&#39;!key&#39;</span> =&gt; $key)));</div>
<div class="line"><a name="l00388"></a><span class="lineno">  388</span>&#160;        }</div>
<div class="line"><a name="l00389"></a><span class="lineno">  389</span>&#160;      }</div>
<div class="line"><a name="l00390"></a><span class="lineno">  390</span>&#160;      $sql = <a class="code" href="sql_8drush_8inc.html#a828cf565e2e7e569e41c3fbe8a8e0cf0">drush_sql_get_class</a>($db_spec);</div>
<div class="line"><a name="l00391"></a><span class="lineno">  391</span>&#160;      $sql-&gt;drop_or_create();</div>
<div class="line"><a name="l00392"></a><span class="lineno">  392</span>&#160;      $sql-&gt;query(NULL, $sql_file);</div>
<div class="line"><a name="l00393"></a><span class="lineno">  393</span>&#160;</div>
<div class="line"><a name="l00394"></a><span class="lineno">  394</span>&#160;      <span class="comment">// Append new DB info to settings.php.</span></div>
<div class="line"><a name="l00395"></a><span class="lineno">  395</span>&#160;      <span class="keywordflow">if</span> ($db_url) {</div>
<div class="line"><a name="l00396"></a><span class="lineno">  396</span>&#160;        $settingsfile = $destination . <span class="charliteral">&#39;/&#39;</span> . $site[<span class="stringliteral">&#39;sitedir&#39;</span>] . <span class="stringliteral">&#39;/settings.php&#39;</span>;</div>
<div class="line"><a name="l00397"></a><span class="lineno">  397</span>&#160;        <span class="comment">//If settings.php doesn&#39;t exist in the archive, create it from default.settings.php.</span></div>
<div class="line"><a name="l00398"></a><span class="lineno">  398</span>&#160;        <span class="keywordflow">if</span> (!file_exists($settingsfile)) {</div>
<div class="line"><a name="l00399"></a><span class="lineno">  399</span>&#160;          <a class="code" href="drush_8inc.html#acebe9ed4e4825e6d33ab8dff2157b676">drush_op</a>(<span class="stringliteral">&#39;copy&#39;</span>, $destination . <span class="stringliteral">&#39;/sites/default/default.settings.php&#39;</span>, $settingsfile);</div>
<div class="line"><a name="l00400"></a><span class="lineno">  400</span>&#160;        }</div>
<div class="line"><a name="l00401"></a><span class="lineno">  401</span>&#160;        <span class="comment">// Need to do something here or else we can&#39;t write.</span></div>
<div class="line"><a name="l00402"></a><span class="lineno">  402</span>&#160;        chmod($settingsfile, 0664);</div>
<div class="line"><a name="l00403"></a><span class="lineno">  403</span>&#160;        file_put_contents($settingsfile, <span class="stringliteral">&quot;\n// Appended by drush archive-restore command.\n&quot;</span>, FILE_APPEND);</div>
<div class="line"><a name="l00404"></a><span class="lineno">  404</span>&#160;        <span class="keywordflow">if</span> (<a class="code" href="drupal_8inc.html#ad2ccab77d4bc8e7355186f26cd328ac0">drush_drupal_major_version</a>($destination) &gt;= 7) {</div>
<div class="line"><a name="l00405"></a><span class="lineno">  405</span>&#160;          file_put_contents($settingsfile, <span class="stringliteral">&quot;\n&quot;</span> . <span class="stringliteral">&#39;$databases = &#39;</span> . var_export(<a class="code" href="sitealias_8inc.html#a96a1545df8b70035ba248ae3cb057d06">drush_sitealias_convert_db_from_db_url</a>($db_url), TRUE) . <span class="stringliteral">&quot;;\n&quot;</span>, FILE_APPEND);</div>
<div class="line"><a name="l00406"></a><span class="lineno">  406</span>&#160;        }</div>
<div class="line"><a name="l00407"></a><span class="lineno">  407</span>&#160;        <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00408"></a><span class="lineno">  408</span>&#160;          file_put_contents($settingsfile, <span class="stringliteral">&quot;\n&quot;</span> . <span class="stringliteral">&#39;$db_url = \&#39;&#39;</span> . $db_url . <span class="stringliteral">&quot;&#39;;\n&quot;</span>, FILE_APPEND);</div>
<div class="line"><a name="l00409"></a><span class="lineno">  409</span>&#160;        }</div>
<div class="line"><a name="l00410"></a><span class="lineno">  410</span>&#160;        <a class="code" href="group__logging.html#ga47324b65808524558a488916b150dd51">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Drush appended the new database configuration at settings.php. Optionally remove the old configuration manually.&#39;</span>), LogLevel::OK);</div>
<div class="line"><a name="l00411"></a><span class="lineno">  411</span>&#160;      }</div>
<div class="line"><a name="l00412"></a><span class="lineno">  412</span>&#160;    }</div>
<div class="line"><a name="l00413"></a><span class="lineno">  413</span>&#160;  }</div>
<div class="line"><a name="l00414"></a><span class="lineno">  414</span>&#160;  <a class="code" href="group__logging.html#ga47324b65808524558a488916b150dd51">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Archive restored to !dest&#39;</span>, array(<span class="stringliteral">&#39;!dest&#39;</span> =&gt; $destination)), LogLevel::OK);</div>
<div class="line"><a name="l00415"></a><span class="lineno">  415</span>&#160;</div>
<div class="line"><a name="l00416"></a><span class="lineno">  416</span>&#160;  <span class="keywordflow">return</span> $destination;</div>
<div class="line"><a name="l00417"></a><span class="lineno">  417</span>&#160;}</div>
<div class="line"><a name="l00418"></a><span class="lineno">  418</span>&#160;</div>
<div class="line"><a name="l00419"></a><span class="lineno">  419</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00420"></a><span class="lineno">  420</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00421"></a><span class="lineno">  421</span>&#160;<span class="comment"> * Command argument complete callback.</span></div>
<div class="line"><a name="l00422"></a><span class="lineno">  422</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00423"></a><span class="lineno">  423</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l00424"></a><span class="lineno">  424</span>&#160;<span class="comment"> *   Strong glob of files to complete on.</span></div>
<div class="line"><a name="l00425"></a><span class="lineno">  425</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00426"></a><span class="lineno"><a class="code" href="archive_8drush_8inc.html#abc741cfce06d40bb144f56987181d030">  426</a></span>&#160;<span class="keyword">function</span> <a class="code" href="archive_8drush_8inc.html#abc741cfce06d40bb144f56987181d030">archive_archive_restore_complete</a>() {</div>
<div class="line"><a name="l00427"></a><span class="lineno">  427</span>&#160;  <span class="keywordflow">return</span> array(</div>
<div class="line"><a name="l00428"></a><span class="lineno">  428</span>&#160;    <span class="stringliteral">&#39;files&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00429"></a><span class="lineno">  429</span>&#160;      <span class="stringliteral">&#39;directories&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00430"></a><span class="lineno">  430</span>&#160;        <span class="stringliteral">&#39;pattern&#39;</span> =&gt; <span class="charliteral">&#39;*&#39;</span>,</div>
<div class="line"><a name="l00431"></a><span class="lineno">  431</span>&#160;        <span class="stringliteral">&#39;flags&#39;</span> =&gt; GLOB_ONLYDIR,</div>
<div class="line"><a name="l00432"></a><span class="lineno">  432</span>&#160;      ),</div>
<div class="line"><a name="l00433"></a><span class="lineno">  433</span>&#160;      <span class="stringliteral">&#39;tar&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00434"></a><span class="lineno">  434</span>&#160;        <span class="stringliteral">&#39;pattern&#39;</span> =&gt; <span class="stringliteral">&#39;*.tar.gz&#39;</span>,</div>
<div class="line"><a name="l00435"></a><span class="lineno">  435</span>&#160;      ),</div>
<div class="line"><a name="l00436"></a><span class="lineno">  436</span>&#160;    ),</div>
<div class="line"><a name="l00437"></a><span class="lineno">  437</span>&#160;  );</div>
<div class="line"><a name="l00438"></a><span class="lineno">  438</span>&#160;}</div>
<div class="line"><a name="l00439"></a><span class="lineno">  439</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00440"></a><span class="lineno">  440</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00441"></a><span class="lineno">  441</span>&#160;<span class="comment"> * Try to find docroot and DB dump file in an extracted archive.</span></div>
<div class="line"><a name="l00442"></a><span class="lineno">  442</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00443"></a><span class="lineno">  443</span>&#160;<span class="comment"> * @param string $path The location of the extracted archive.</span></div>
<div class="line"><a name="l00444"></a><span class="lineno">  444</span>&#160;<span class="comment"> * @return array The manifest data.</span></div>
<div class="line"><a name="l00445"></a><span class="lineno">  445</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00446"></a><span class="lineno"><a class="code" href="archive_8drush_8inc.html#a51085ff955b6905e494c7da6cd84e028">  446</a></span>&#160;<span class="keyword">function</span> <a class="code" href="archive_8drush_8inc.html#a51085ff955b6905e494c7da6cd84e028">drush_archive_guess_manifest</a>($path) {</div>
<div class="line"><a name="l00447"></a><span class="lineno">  447</span>&#160;  $db_file = <a class="code" href="group__filesystemfunctions.html#ga1c545390a8890f6ea47385f79fbe2e82">drush_scan_directory</a>($path, <span class="stringliteral">&#39;/\.sql$/&#39;</span>,  array(<span class="charliteral">&#39;.&#39;</span>, <span class="stringliteral">&#39;..&#39;</span>, <span class="stringliteral">&#39;CVS&#39;</span>), 0, 0);</div>
<div class="line"><a name="l00448"></a><span class="lineno">  448</span>&#160;</div>
<div class="line"><a name="l00449"></a><span class="lineno">  449</span>&#160;  <span class="keywordflow">if</span> (file_exists($path . <span class="stringliteral">&#39;/index.php&#39;</span>)) {</div>
<div class="line"><a name="l00450"></a><span class="lineno">  450</span>&#160;    $docroot = <span class="stringliteral">&#39;./&#39;</span>;</div>
<div class="line"><a name="l00451"></a><span class="lineno">  451</span>&#160;  }</div>
<div class="line"><a name="l00452"></a><span class="lineno">  452</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00453"></a><span class="lineno">  453</span>&#160;    $directories = glob($path . <span class="stringliteral">&#39;/*&#39;</span> , GLOB_ONLYDIR);</div>
<div class="line"><a name="l00454"></a><span class="lineno">  454</span>&#160;    $docroot = reset($directories);</div>
<div class="line"><a name="l00455"></a><span class="lineno">  455</span>&#160;  }</div>
<div class="line"><a name="l00456"></a><span class="lineno">  456</span>&#160;</div>
<div class="line"><a name="l00457"></a><span class="lineno">  457</span>&#160;  $ini = array(</div>
<div class="line"><a name="l00458"></a><span class="lineno">  458</span>&#160;    <span class="stringliteral">&#39;Global&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00459"></a><span class="lineno">  459</span>&#160;        <span class="comment">// Very crude detection of a platform...</span></div>
<div class="line"><a name="l00460"></a><span class="lineno">  460</span>&#160;        <span class="stringliteral">&#39;archiveformat&#39;</span> =&gt; (<a class="code" href="drupal_8inc.html#a203e989fd043d054d774954e2b2dff21">drush_drupal_version</a>($docroot) ? <span class="stringliteral">&#39;platform&#39;</span> : <span class="stringliteral">&#39;site&#39;</span>),</div>
<div class="line"><a name="l00461"></a><span class="lineno">  461</span>&#160;    ),</div>
<div class="line"><a name="l00462"></a><span class="lineno">  462</span>&#160;    <span class="stringliteral">&#39;default&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00463"></a><span class="lineno">  463</span>&#160;      <span class="stringliteral">&#39;docroot&#39;</span> =&gt; $docroot,</div>
<div class="line"><a name="l00464"></a><span class="lineno">  464</span>&#160;      <span class="stringliteral">&#39;sitedir&#39;</span> =&gt; <span class="stringliteral">&#39;sites/default&#39;</span>,</div>
<div class="line"><a name="l00465"></a><span class="lineno">  465</span>&#160;      <span class="stringliteral">&#39;database-default-file&#39;</span> =&gt; key($db_file),</div>
<div class="line"><a name="l00466"></a><span class="lineno">  466</span>&#160;    ),</div>
<div class="line"><a name="l00467"></a><span class="lineno">  467</span>&#160;  );</div>
<div class="line"><a name="l00468"></a><span class="lineno">  468</span>&#160;</div>
<div class="line"><a name="l00469"></a><span class="lineno">  469</span>&#160;  <span class="keywordflow">return</span> $ini;</div>
<div class="line"><a name="l00470"></a><span class="lineno">  470</span>&#160;}</div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Wed Nov 2 2016 07:28:50 for Drush by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.1.2
</small></address>
</body>
</html>