sde automatically backed up to a file gdb

This principle of the method is to use python (hereinafter referred to as py) call arcmap of gp, implemented on a call and then bat py way. The advantage is applicable to all types of databases (including pg, oracle, etc.) of the library sde

 

Environment: arcmap 10.4, pg version sde

 

In this paper, the following sde backup feature class, backup to the local D: \ test1 folder below gdb, backup interval is once a day

 

 

 

Py is a backup script language, provides the following templates:

 

Template begin ----------------------------

#coding:utf-8

# Import arcpy module

import arcpy

import datetime

 

# Backup local file folder path gdb

bak_gdb_path = "D:\\test1"

# Backup local files gdb file name (do not bring .gdb)

bak_gdb_name="bak_xxx"

 

# Get the current date and with a specified output format (in this case all nearest days backed up daily, there is need to output the current time in other formats can search its own date and time of the output py)

today=datetime.date.today()

formatted_today=today.strftime('%Y%m%d')

 

# Ultimate gdb file name

bak_gdb_name_final=bak_gdb_name+"_"+formatted_today

 

# Process: Create a file geodatabase

arcpy.CreateFileGDB_management(bak_gdb_path, bak_gdb_name_final, "CURRENT")

 

# Copy feature class (sde is to copy the feature class to GDB, this backup method), a copy of each line feature class, to copy a plurality of feature classes, may be replaced by a text editor or the like excel Batch time by format modify

Parameter # 1: sde feature class path, the path format to export import functions in use to see arcmap

Parameter # 2: Copy the path of gdb, generally do not change

arcpy.FeatureClassToGeodatabase_conversion ( "\\ connected to the database connection sde_demo.sde \\ sde_demo.sde.data \ sde_demo.sde.SDE_DEMO_POLYGON", bak_gdb_path + "\\" + bak_gdb_name_final + ". gdb")

 

Template ended ----------------------------

 

In any directory, create a py file (in this case the file name is test21.py), copy the content into the template, and then start the actual modifications described below to change the

 

Local output file location

 

 

  

Generally do not change

 

 

  

The main change parameters 1, there is a problem is how to determine the feature class to guide sde "path"? And how to quickly generate when you need to export more feature classes? To open gp easily find a feature class, the class loading feature will become route feature class, batch execution gp also acquired a plurality (line version), and binds excel, notepad etc. batch processing text substitution character the approach

 

 

  

Py finished editing this file, and then manually invoke automatic test run

 

Arcmap used to call py file that comes with python (py comes when arcmap installation, and here comes this must also be used, and can not own equipment py original)

PS: arcmap comes py to have a sign is installed there ArcGIS10.4 (name varies according to ArcGIS version) directory folder

 

 

  

cmd to this file py installation directory folder

 

 

  

cmd Run: python D: \ test1 \ test21.py, wherein the back of the file path according to the actual change

Successful implementation of the way

 

  

Then take a look at whether the backup gdb generation, whether correct data replication

 

Description py script this is normal, then start configuring the timing of execution

 

First, a new bat py files in the file folder backup script, in this case called test21.bat

 

 

 

It reads as follows:

Preceding paragraph is arcgis comes python.exe py's location, location is behind the py file backup script

 

 

 "C:\Python27\ArcGIS10.4\python" D:\arcpy_test\test1.py

 

Then start a new scheduled task, perform regular scheduled tasks using the windows (you can also use regular implementation of jenkins), this it should be more familiar, but also useful to the mysql automatic backup, below only illustrate key position

 

New content is automatically performed above bat file

 

 

  

Automatic configuration is complete this task, attention is likely to perform automatic task execution failure or other problems (manually executed successfully does not mean automatic execution will succeed), to observe the follow-up after one or two really be considered truly successful success

Guess you like

Origin www.cnblogs.com/cannel/p/11503231.html