Backup your data and code from any SN instance

General Add comments
by:

data-backup-tape
As a service-now developer every few months I have the need to lookup a piece of code or check on some data or property setting from a while ago. Although in service-now most things are is auditable and with some searching in the system you often can find the old data or code, not all things are traceable and when you clone environments all data is gone.
Therefore, during projects, I frequently like to make a backup of code and data of instances I’m working on. All the forms/tables that contain relevant data for future reference are included in the backup.
For this purpose I created a simple shellscript that runs on my Mac which creates one zip file ready to archive.

The export format of the files in the zip file are in what service-now calls “useUnloadFormat”. This means that the format is XML which call also be uploaded again.

This script contains 5 variables that must be set before running the script (one time setting per environment you want to backup).
-user = the service-now account that has access to all the data you want to export. Usually the admin account
-pwd = password for the user account
-instance = the service-now instance name
-dir = the directory where the zip file will be created on you computer
-table = array of all the forms you want the backup

The name of the zip file contains the instance name and the date on which it is created.

See below for a sample script.

Instructions on how to use it (on a Mac):
-Just copy the script and save it on you machine. For example “sn_export.sh”.
-Update the variables in the script mentioned above.
-Open a terminal and navigate to the directory where you saved the file.
-Type in “./sn_export.sh” and hit the return.

Is feels a bit old fashioned to create you own backups, but is several cases for me it was very helpful. Maybe in the future it will save your day.


#Service-now export of all configuration tables to XML unload format (this format can be uploaded again)
#The export is stored on the desktop
#!/bin/sh

user=admin
pwd=admin
instance=demo001
dir=~/Desktop
table=()
table+=(expert_script_client)
table+=(expert_survey)
table+=(expert_ui_policy)
table+=(expert_variable)
table+=(survey_conditions)
table+=(survey_master)
table+=(survey_question_new)
table+=(sys_app_application)
table+=(sys_certificate)
table+=(sys_choice)
table+=(sys_data_policy2)
table+=(sys_db_view)
table+=(sys_dictionary_override)
table+=(sys_dictionary)
table+=(sys_documentation)
table+=(sys_installation_exit)
table+=(sys_portal_page)
table+=(sys_processor)
table+=(sys_properties)
table+=(sys_relationship)
table+=(sys_script_client)
table+=(sys_script_include)
table+=(sys_script)
table+=(sys_security_acl)
table+=(sys_table_rotation)
table+=(sys_transform_entry)
table+=(sys_transform_map)
table+=(sys_transform_script)
table+=(sys_ui_action)
table+=(sys_ui_bookmark)
table+=(sys_ui_macro)
table+=(sys_ui_message)
table+=(sys_ui_policy)
table+=(sys_ui_style)
table+=(sys_web_service)
table+=(sys_web_service_input)
table+=(sys_web_service_output)
table+=(sysauto)
table+=(sysauto_script)
table+=(sysevent_email_action)
table+=(sysrule_view)
table+=(ts_group)
table+=(wf_activity)
table+=(wf_activity_definition)
table+=(wf_activity_variable)
table+=(wf_condition)
table+=(wf_condition_default)
table+=(wf_stage)
table+=(wf_stage_default)
table+=(wf_workflow_version)
table+=(wf_transition)
table+=(sys_user_role)
table+=(sys_user_group)
table+=(sys_group_has_role)
table+=(core_company)
table+=(service_offering)
table+=(service_commitment)
table+=(service_offering_commitment)
table+=(service_offering_sla)
table+=(service_subscribe_company)
table+=(cmn_schedule)
table+=(cmn_schedule_span)

cd $dir
mkdir myExportDir
cd $dir/myExportDir

for i in ${table[@]}
do
curl -O https://$user:$pwd@$instance.service-now.com/$i.do?XML&useUnloadFormat=true &
done

wait
dt=$(date +%Y%m%d)
cd $dir
tar cvf - myExportDir | gzip > $instance-$dt.zip &

wait
rm -r $dir/myExportDir

echo "EXPORT DONE"

If you need more information, please let me know via comment or send an email: .img[at].img

2 Responses to “Backup your data and code from any SN instance”

  1. Chris Royer Says:

    So I wanted to point out a couple of things to note while doing this. If you have an certain symbols in your username or password you want to escape them i.e. @ becomes %40.

    I also had issues(command not found, just ran the command as “/bin/bash sn_export.sh”) running the shell on my OSX machine, if you’re not in the mood for troubleshooting keep in mind that the mac terminal allows you to paste the entire script in if you wanted.

    This has been a good learning experience with using cURL, and thinking about creating a Powershell equivalent.

  2. Neal Ratner Says:

    Running this with Istanbul and getting “permission denied.” I used your same exact tables to test. Has anyone tried this recently or is there an update?

Leave a Reply