Restore your installation from a backup

Prev Next

If you manually created a backup of your Lansweeper installation, you can restore it at a later date. Which procedure you follow depends on which database server hosts your database.

An Easy install hosts your database in SQL LocalDB. An Advanced install lets you choose between SQL LocalDB and SQL Server. SQL Compact was the database server on installations predating March 2020 and is no longer supported, so if you're still on it, convert your database instead of restoring back onto it.

If you're unsure which database server you're using, see how to identify your database server.

Restore a backup on SQL Compact

  1. Stop the Lansweeper Server service in Windows Services.

  2. Stop the Lansweeper Auto-update service in Windows Services.

  3. Stop your web server service in Windows Services. Keep in mind that this will log everyone out of the console. Your web server service is either IIS Express or World Wide Web Publishing Service (IIS).

  4. Make sure your database backup file is called lansweeperdb.sdf and place it in Program Files (x86)\Lansweeper\SQLData, overwriting the database file currently present in the folder.

  5. Restore the Website subfolders and Encryption.txt file you created a backup of.

  6. Restart the Lansweeper and web server services in Windows Services.

Restore a backup on SQL Server or SQL LocalDB

  1. Stop the Lansweeper Server service in Windows Services.

  2. Stop the Lansweeper Auto-update service in Windows Services.

  3. Stop your web server service in Windows Services. Keep in mind that this will log everyone out of the console. Your web server service is either IIS Express or World Wide Web Publishing Service (IIS).

  4. Right-click the lansweeperdb database in SQL Server Management Studio and select Tasks > Restore > Database... to open the restore wizard. If SQL Server Management Studio isn't installed on your Lansweeper server, we recommend downloading it online.

  5. In the General tab of the restore wizard, select the correct destination (lansweeperdb) and source for the restore operation. If your backup is a .bak file, select the Device option under Source and select the button with the three dots to open a pop-up where you can select your file.

    If you're restoring a SQL LocalDB database, do not change the file path of your mdf and ldf files in the Files tab. They must be stored in the Lansweeper\SQL Data folder. The Restore As path in the Files tab must be the Lansweeper\SQL Data folder belonging to your Lansweeper database.

  6. In the Options tab of the restore wizard, tick Overwrite The Existing Database, and select OK to perform the database restore.

    Make sure the overwrite box is checked. Otherwise, the following error may be generated: "The backup set holds a backup of a database other than the existing 'lansweeperdb' database."

  7. Log into SQL Server Management Studio with a user that has sysadmin rights. Then execute the following script to reset the lansweeperuser SQL user used by the Lansweeper service and web console to connect to the database. Replace 'lansweeperuserpassword' with the password you want to set for lansweeperuser, leaving the single quotes in the script.

    /* Makes sure there are no objects in the lansweeperuser schema, so the lansweeperuser SQL user can be reset */
    USE lansweeperdb
    GO
    IF EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'lansweeperuser')
    BEGIN
        DECLARE c_ALTSCHEMA CURSOR FOR
        SELECT 'ALTER SCHEMA dbo TRANSFER lansweeperuser.' + name + ';'
        FROM sys.objects
        WHERE SCHEMA_NAME(SCHEMA_ID) = 'lansweeperuser'
    
        DECLARE @SQLStmt NVARCHAR(200)
        OPEN c_ALTSCHEMA
        FETCH NEXT FROM c_ALTSCHEMA INTO @SQLStmt
        WHILE @@FETCH_STATUS = 0
        BEGIN
            EXEC(@SQLStmt)
            FETCH NEXT FROM c_ALTSCHEMA INTO @SQLStmt
        END
        CLOSE c_ALTSCHEMA
        DEALLOCATE c_ALTSCHEMA
    END
    GO
    
    /* Resets the lansweeperuser SQL user */
    USE lansweeperdb
    GO
    IF EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'lansweeperuser')
        DROP SCHEMA lansweeperuser
    GO
    IF EXISTS (SELECT 1 FROM sys.database_principals WHERE name = 'lansweeperuser')
        DROP USER lansweeperuser
    GO
    USE MASTER
    GO
    IF EXISTS (SELECT 1 FROM sys.server_principals WHERE name = 'lansweeperuser')
        DROP LOGIN lansweeperuser
    GO
    CREATE LOGIN lansweeperuser
        WITH PASSWORD = 'lansweeperuserpassword',
        CHECK_POLICY = OFF,
        DEFAULT_DATABASE = lansweeperdb,
        DEFAULT_LANGUAGE = [English]
    GO
    USE lansweeperdb
    GO
    CREATE USER lansweeperuser FOR LOGIN lansweeperuser
    GO
    EXEC sp_addrolemember [db_owner], 'lansweeperuser'
    GO
    
    /* Optional step to grant lansweeperuser additional permissions, which are required for syncing with Cloud */
    USE MASTER
    GO
    ALTER SERVER ROLE [dbcreator] ADD MEMBER [lansweeperuser]
    GO
    GRANT VIEW SERVER STATE TO lansweeperuser
    GO
    

    Don't skip this step. Restoring a database backup almost always corrupts the SQL user used by the Lansweeper service and web console to connect to the database. If you don't reset the user, the service and web console will be unable to connect to the database.

  8. Run the ConfigEditor tool on the server(s) hosting your Lansweeper Server service and web console. The tool can be found at Program Files (x86)\Lansweeper\Tools\ConfigEditor.exe.

  9. Click through any warnings the tool may be giving you about your password being incorrect.

  10. Select the Password field and select Edit.

  11. Enter the same password you used in the database script and select Save to close the edit dialog.

  12. If the ConfigEditor tool has multiple tabs due to your server hosting multiple Lansweeper components, select the other tab, click through any warnings and repeat the password-changing process.

  13. Select Save in the main ConfigEditor window to write the new configuration to disk.

  14. Restore the Website subfolders and Encryption.txt file you created a backup of. Restore only these folders.

  15. Restart the Lansweeper and web server services in Windows Services.

  16. If you have multiple scanning servers, update the database password on those servers by stopping the Lansweeper service, using the ConfigEditor tool and restarting the service.