Base solution for your next web application
Open Closed

Someone help me - Backup Tenant to another Database #2155


User avatar
0
luizluan created

For legal reasons I must provide a backup file for the client with .bak extension. The problem is that my database has data from all clients and has no way of providing the backup of everyone.

Is there a way to make a backup with the tenant data and schema in another database?

I would appreciate it if anyone could help me. :D


4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    This is not an easy job I think. I dont know if there are some tools do this but you can check for that first.

    If you cannot find something like that, you can do it in a few steps like this. 1 ) Create a second DB for backup. 2 ) Apply migrations to it. 3 ) Disable Identity AutoIncrements and Foreign Keys manually. 3 ) Use SQL's data export for exporting tenant's data to your new DB. Here you can use a query to select data from necessary tables. 4) Enable Identity AutoIncrements and Foreign Keys manually.

    I'm not an expert on Databases, maybe someone else can offer you a better solution.

  • User Avatar
    0
    luizluan created

    Also I am not good with database scripts. My friend set the script for me.

    I the script does the following: Database Backup Delete everything that is with the different Tenant

    Then I did some extra scripts to clean tables that have no tenants.

    After that I generate a bak and drop the temporary database, after that I have a backup only with the tenant data I passed as a parameter.

    You can add the stored procedure to the migration file.

    Happy End.

  • User Avatar
    0
    ismcagdas created
    Support Team

    I'm glad that you find a solution :)

  • User Avatar
    0
    luizluan created

    If someone has a transaction error while backing up, just add 'Enlist = false;' At the end of the string connection. :mrgreen: