Powershell script – create folder and zip – backup

You have a folder that you would like to compress with one click and save the result to a specific folder and file name. To have a regular backup and archive, multiple backup files e.g. every night or on each user logon/logoff should be created.

The following simple powershell scripts allow to compress the content of a folder and create a zip file on another location. This can be used e.g. as a simple backup solution.


The following scripts require Powershell 4/5 for Windows, and Powershell 6 for Mac/Linux/arm user (using Powershell Core).

Simple script – zip file for directory with same target file name

The following powershell script creates a zip file based from $sourceDir and writes the result to $targetFile .

$sourceDir = 'c:\data';
$targetFile = 'c:\backup\data.zip'

## no changes here
Add-Type -A 'System.IO.Compression.FileSystem';
[IO.Compression.ZipFile]::CreateFromDirectory($sourceDir, $targetFile);

Advanced script – zip backup file with target filename including timestamp

The following advanced powershell script creates a zip file based on the content of the folder $sourceDir. The output is written to a file named “data-” and the current timestamp, located in the $targetDir.

$sourceDir = 'c:\data';
$targetDir = 'c:\backup\'
$targetFilenameBase = 'data-';

## no changes here
$date = get-date;
$dateStr = $date.ToString("yyyy-MM-dd_HH-mm");
$targetFile = $targetDir+$targetFilenameBase+$dateStr+'.zip';

Add-Type -A 'System.IO.Compression.FileSystem';
[IO.Compression.ZipFile]::CreateFromDirectory($sourceDir, $targetFile);

How to use the backup powershell script

Just copy the content of one of the solutions in a text editor or the Windows PowerShell Integrated Scripting Environment (ISE) , save the result to a file as e.g. create_backup.ps1 and run it.

Other solutions

Windows 10 provides further backup application and features – with some advanced features, that require addition settings and hardware.

Powershell 7 provides also features to create and decompress zip files with the functions Compress-Archive and Expand-Archive .

search files by content text using find and grep


This post is about a simple task – but I always forget the syntax. Search recursively for files inside the current directory with a special text in the file content.

find . -name "*.*" -print | xargs grep "SEARCHTEXT" --color=auto

This snippet searches for all files of the current directory that match the name parameter *.* (so you could e.g. search for all .css files with -name “*.css”). The result is displayed with grep – using the nice color-highlighting.

This is especially useful for remove access on linux machines or other unix-based devices.

Plesk 8 installation on debian 4

Installing Plesk 8.x on debian 4.x “etch” seems a bit uncommon, but the mixture of a rockstable and secure base system as debian and the common webserver management interface Plesk makes sense.

How to install Plesk on debian

  1. Install a fresh debian and perform a dist-upgrade:
    apt-get update && apt-get dist-upgrade
  2. Add the following line to the apt sources list located at /etc/apt/sources.list (replace 8.2.1 and etch with your versions)
    deb http://autoinstall.plesk.com/debian/PSA_8.2.1 etch all
  3. Force apt-get to update database with new information from Plesk
    apt-get update
  4. Install Plesk base system with apt-get, say Yes to accept the packages from Plesk that have a problematic signature.
    apt-get install psa
  5. Install Plesk Autoupdate module with apt-get:
    apt-get install psa-autoinstaller
  6. Install package with PHP5 suport for Plesk
    apt-get install psa-php5-configurator
  7. Restart PSA – don’t forget this! Otherwise you’ll get 404 errors instead the login page.
    /etc/init.d/psa restart
  8. Access the fresh installed Plesk interface with your browser (replace your-server-name with the url/ip of your server). The default login is admin, the default password setup.
  9. That’s it. The rest can be done via the Plesk interface.

More information can be found in the Plesk v8.2.1 build82070918.10 for Debian-4.0 x86_64 Release Notes.

Change admin password

Change admin password in Plesk

Plesk provides a nice script to change the admin password: /usr/local/psa/admin/bin/ch_admin_passwd

More information how to use it can be found at http://support.theplanet.com/knowledgebase/users/kb.php?id=10598

You should shutdown mysql before performing this and not break the execution of the script. It takes some time! Otherwise you might get this:

Broken database PSA in MySQL

After changing the passwort as described above, the following error message was displayed in the mysql log file and on the console – e.g. when starting plesk.:

Incorrect information in file: psa/xxx.frm

This indicates a broken database index. Since the tables in the psa database are InnoDB tables, the InnoDB recovery tools are interesting. I tried and googled for about an hour, without success. Finally, I just tried to restart the whole server. And then the server was available again, Plesk was running and the errors where gone.

What was the reason? Interupting the password changing script might have caused the trouble. The database files haven’t been closed properly on the filesystem level, which has been fixed with the reboot of the operating system.