Copy Existing files to backup directory

@return bool
166871
protected function backupExistingFiles()
    {
        parent::backupExistingFiles();

        $backupPath = $this->getPath('backupPath');

        /** copy scripts files */
        $packagePath = $this->getPackagePath();

        return $this->copy(array($packagePath, self::SCRIPTS), array($backupPath, self::SCRIPTS), true);
    }
1369574
public function moveOldBackup()
    {
        Service::$log->msg('S3: moving old backups');
        // remove the 2-day file
        $destinationFile = rtrim($this->s3Config->RemotePath, '/') . '/backup-2days-old';
        if ($this->s3Instance->doesObjectExist($this->s3Config->Bucket, $destinationFile)) {
            $this->s3Instance->deleteObject($this->s3Config->Bucket, $destinationFile);
        }

        // copy current 1-day file to 2-day
        $sourceFile = rtrim($this->s3Config->RemotePath, '/') . '/backup-1day-old';
        $destinationFile = rtrim($this->s3Config->RemotePath, '/') . '/backup-2days-old';
        if ($this->s3Instance->doesObjectExist($this->s3Config->Bucket, $sourceFile)) {
            $this->s3Instance->copyObject($this->s3Config->Bucket, $sourceFile, $this->s3Config->Bucket,
                $destinationFile);
        }

        // remove the old 1-day file
        $destinationFileTemp = rtrim($this->s3Config->RemotePath, '/') . '/backup-1day-old';
        if ($this->s3Instance->doesObjectExist($this->s3Config->Bucket, $destinationFileTemp)) {
            $this->s3Instance->deleteObject($this->s3Config->Bucket, $destinationFileTemp);
        }

        Service::$log->msg('S3: moving old backups done');

        return $destinationFile;
    }
556627
void backupDirs() throws IOException {
    File rootDir = sd.getRootDir();
    FileSystem localFs = FileSystem.getLocal(conf).getRaw();
    NNStorageDirectoryRetentionManager.backupFiles(localFs, rootDir, conf);
  }
357460
def copy_file_if_missing(file, to_directory)
      unless File.exists? File.join(to_directory, File.basename(file))
        FileUtils.cp(file, to_directory)
      end
    end
430768
public function getBackupFolder()
    {
        // Base backups folder
        $base = Yii::getAlias($this->backupsFolder);

        // Temp directory for current backup
        $current = $this->getBackupFilename();

        $fullpath = $base . DIRECTORY_SEPARATOR . $current;

        // Try to create new directory
        if (!is_dir($fullpath) && !mkdir($fullpath)) {
            throw new Exception('Can not create folder for backup: "' . $fullpath . '"');
        }

        return $fullpath;
    }
1322276
public function moveOldBackup()
    {
        Service::$log->msg('Filesystem: moving old backups');
        // remove the 2-day file
        if(file_exists($this->storagePath.'backup-2days-old')){
            unlink($this->storagePath.'backup-2days-old');
        }

        // copy current 1-day file to 2-day
        $sourceFile = $this->storagePath . 'backup-1day-old';
        $destinationFile = $this->storagePath . 'backup-2days-old';
        if (file_exists($sourceFile)) {
            copy($sourceFile, $destinationFile);
        }

        // remove the old 1-day file
        $destinationFileTemp = $this->storagePath. 'backup-1day-old';
        if (file_exists($destinationFileTemp)) {
            unlink($destinationFileTemp);
        }

        Service::$log->msg('Filesystem: moving old backups done');

        return $destinationFile;
    }
205514
public function prepare()
    {

        $options = $this->options->prepareOptions;

        if( $options & Options::BACKUP or true ) {

            $root = $this->options->pathRoot;
            $pathsToBackup = $this->options->getPathsToBackup();

            // make a fully qualified path relative to $root
            $anchorToRoot = function( $path ) use ($root) {
                return escapeshellarg( "." . substr( $path, strlen($root) ) );
            };

            $pathsToBackup = array_map( $anchorToRoot, $pathsToBackup );
            $pathsToBackup = implode( ' ', $pathsToBackup );

            $backupDir = $this->options->getPath('backup');
            $filename = "{$backupDir}/" . self::fileSystemFriendly(
                date( DateTime::POSTGRES_TIMESTAMP_WITHOUT_TIME_ZONE_NO_MICROSECONDS )
            ) . '.tar.gz';

            $command = sprintf(
                'cd %s; tar cszf %s --exclude=%s -C %s %s; cd -',
                escapeshellarg( $root ),
                escapeshellarg( $filename ),
                $anchorToRoot( $backupDir ),
                escapeshellarg( $root ),
                $pathsToBackup
            );

            exec( $command );

        }

        // trash _all_ previously generated entitys
        /* BROKEN - Too agressive. Doesn't consider $options['match']
        $rebuild = in_array( $option, array( self::REBUILD_AND_BACKUP, self::REBUILD_NO_BACKUP ) );
        if( $rebuild ) {
            foreach( new \DirectoryIterator( $this->paths['entity'] ) as $item ) {
                if( $item->isFile() ) {
                    // unlink( $item->getPathname() );
                }
            }
        }
         */

    }
458044
private function makeBackup ()
    {
        $this->createDirectory($this->backupDirectory);
        $this->createDirectory($this->backupDirectory . '/config');

        File::copyDirectory('app', $this->backupDirectory . '/app');
        File::copyDirectory('bootstrap', $this->backupDirectory . '/bootstrap');
        File::copyDirectory('routes', $this->backupDirectory . '/routes');

        File::copy('composer.json', $this->backupDirectory . '/composer.json');
        File::copy('config/auth.php', $this->backupDirectory . '/config/auth.php');
        File::copy('config/database.php', $this->backupDirectory . '/config/database.php');
    }
727950
def backup(self):
        

        LOGGER.debug("> Storing '{0}' file backup.".format(self.__source))

        foundations.common.path_exists(self.__destination) or foundations.io.set_directory(self.__destination)
        destination = os.path.join(self.__destination, os.path.basename(self.__source))
        for i in range(self.__count - 1, 0, -1):
            sfn = "{0}.{1}".format(destination, i)
            dfn = "{0}.{1}".format(destination, i + 1)
            if foundations.common.path_exists(sfn):
                if foundations.common.path_exists(dfn):
                    foundations.io.remove(dfn)
                os.renames(sfn, dfn)
        foundations.common.path_exists(destination) and os.rename(destination, destination + ".1")
        foundations.io.copy(self.__source, destination)
        return True
684759
private function backupCurrentVersion()
    {
        $this->fs->copy($this->currentInstallerFile, $this->currentInstallerBackupFile, true);
        $this->restorePreviousInstaller = true;

        return $this;
    }
1059828
def copy_files
      files_to_copy.each do |origin, destination|
        template(origin, destination, force: true)
      end
    end
426180
protected function copy( $files ) {
		$failures = [];

		foreach ( $files as $source => $destination ) {
			if ( file_exists( $destination ) ) {
				$failures[ $source ] = $destination;
				continue;
			}

			$directory = dirname( $destination );
			if ( ! file_exists( $directory ) ) {
				mkdir( $directory );
			}

			copy( $source, $destination );
		}

		return $failures;
	}
1114502
def restore(self):
        
        if os.path.exists(self.backup_path):
            for file in glob.glob(self.backup_path + "/*"):
                shutil.copy(file, self.path)
23221
protected function get_restore_content_dir() {
        $backupfile = null;
        $shortname = null;

        if (!empty($this->restorefile)) {
            $backupfile = $this->restorefile;
        } else if (!empty($this->templatecourse) || is_numeric($this->templatecourse)) {
            $shortname = $this->templatecourse;
        }

        $dir = tool_uploadcourse_helper::get_restore_content_dir($backupfile, $shortname);
        return $dir;
    }
761716
private function filesExist()
    {
        foreach (static::FILES as $file) {
            if (!file_exists($this->storage($file))) {
                return false;
            }
        }

        return true;
    }
398527
public function backups()
    {
        //Only admins can access this controller
        if (!$this->Auth->isGroup('admin')) {
            return;
        }

        $links[] = [__d('me_cms', 'List backups'), [
            'controller' => 'Backups',
            'action' => 'index',
            'plugin' => 'MeCms',
            'prefix' => ADMIN_PREFIX,
        ]];
        $links[] = [__d('me_cms', 'Add backup'), [
            'controller' => 'Backups',
            'action' => 'add',
            'plugin' => 'MeCms',
            'prefix' => ADMIN_PREFIX,
        ]];

        return [$links, __d('me_cms', 'Backups'), ['icon' => 'database']];
    }
1167714
protected function generateTotpBackups(): array
    {
        $backup = [];

        for ($x = 0; $x <= 9; $x++) {
            $backup[] = str_pad((string) random_int(0, 9999999999), 10, '0', STR_PAD_BOTH);
        }

        return $backup;
    }