Backing up your data..

Modified on Wed, 28 Aug at 4:08 PM

If you are interested in keeping a local copy of your data here is practical way to complete this. In order for this to work you will need the Advanced Data Access feature in order for this to be an option 



Add SQLCMD To the PC that you would like to use:


Option 1: Install SQLCMD via Microsoft ODBC Driver for SQL Server

This is the recommended approach if you only need sqlcmd and not the full suite of SQL Server tools.

  1. Download the Microsoft ODBC Driver for SQL Server:

    • Visit the official Microsoft download page for ODBC Driver for SQL Server.
    • Download the latest version of the ODBC driver compatible with your system (Windows 11 should support most recent versions).
  2. Download the Command Line Utilities:

    • On the same page, look for the "Command Line Utilities" download link. This package includes sqlcmd and bcp.
    • Download and run the installer.
  3. Install the Utilities:

    • Follow the on-screen instructions to install the utilities.
    • By default, sqlcmd will be added to your system's PATH, so you can use it directly from the command prompt or PowerShell.

Option 2: Install SQL Server Management Studio (SSMS)

If you need a graphical interface for SQL Server management along with sqlcmd, installing SSMS might be a better option.

  1. Download SQL Server Management Studio:

  2. Install SSMS:

    • Run the installer and follow the on-screen instructions.
    • sqlcmd is installed automatically as part of SSMS, and it will be added to your system's PATH.


Create a backup.bat file. Add the following to it:

@echo off

REM Define variables for database connection

set server_name=tcp:myserver.database.windows.net,1433

set database_name=evo

set username=myUsername

set password=myPassword

REM Define where the output should be stored. 

set output_folder=C:\Exports


REM Delete all existing .sql files in the output folder 

del %output_folder%\*.sql /Q


REM Read tables from the configuration file

for /F "tokens=*" %%t in (backuptables.conf) do (

    sqlcmd -S %server_name% -d %database_name% -U %username% -P %password% -Q "SELECT * FROM schema_name.%%t" -o "%output_folder%\%%t.sql"

    echo Exported %%t to %output_folder%\%%t.sql

)


echo Data export completed.

pause




Step-by-Step Guide to Schedule a Script in Windows Task Scheduler

1. Open Task Scheduler

  1. Access Task Scheduler:
    • Press Win + S to open the search bar.
    • Type Task Scheduler and press Enter to open the Task Scheduler application.

2. Create a New Task

  1. Create a Basic Task:

    • In the Task Scheduler window, click on Create Basic Task on the right side under the Actions pane.
  2. Name Your Task:

    • Give your task a meaningful name (e.g., Export SQL Data).
    • Optionally, add a description for clarity (e.g., This task exports data from SQL tables to .sql files).
    • Click Next.
  3. Choose When to Start the Task:

    • Choose how often you want the task to run: Weekly, Monthly, etc.
    • Click Next and specify the exact time and frequency according to your needs.
    • Click Next.
  4. Set the Action to Start a Program:

    • Choose Start a program as the action to perform.
    • Click Next.

3. Configure the Task to Run Your Script

  1. Select the Script or Program to Run:

    • In the Program/scriptfield:
      • For a batch script (.bat), browse and select your backup.bat file.
  2. Start In (Optional):

    • Optionally, set the Start in field to the directory where your script resides. This can be helpful if your script depends on relative paths.
  3. Finish the Task Setup:

    • Click Next to review your task details.
    • Click Finish to create the task.

4. Adjust Advanced Settings (Optional)

  1. Open Task Properties:

    • Find your newly created task in the Task Scheduler Library.
    • Right-click the task and select Properties.
  2. General Tab:

    • Check Run whether user is logged on or not if you want the task to run without requiring user logon.
  3. Triggers Tab:

    • You can add additional triggers here, such as running the task on system startup or when a specific event occurs.
  4. Conditions Tab:

    • Adjust conditions like only starting the task if the computer is idle, or if it's on AC power (useful for laptops).
  5. Settings Tab:

    • Set options like allowing the task to be run on demand, stopping the task if it runs longer than expected, etc.
  6. Security Options:

    • Make sure to choose Run with highest privileges if your script requires administrative rights.
  7. Save Changes:

    • Click OK to save your settings.

5. Test the Task

  1. Run the Task Manually:
    • In Task Scheduler, right-click on your task and select Run to test it immediately.
    • Check your output folder to verify that the script ran successfully and generated the expected files.





Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article