%3CLINGO-SUB%20id%3D%22lingo-sub-1532484%22%20slang%3D%22en-US%22%3EBest%20practices%20of%20how%20to%20use%20ADF%20copy%20activity%20to%20copy%20new%20files%20only%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1532484%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20on-going%20ELT%20scenario%2C%20how%20to%20easily%20load%20new%20files%20only%20after%20an%20initial%20full%20data%20loading%20is%20a%20very%20common%20use%20case.%20One%20of%20the%20typical%20examples%20is%20that%20files%20can%20be%20continually%20dropped%20to%20a%20landing%20folder%20of%20your%20source%20store%2C%20where%20you%20want%20an%20easy%20way%20to%20copy%20the%20new%20files%20only%20to%20data%20lake%20store%20instead%20of%20repeatedly%20copy%20any%20files%20which%20have%20already%20been%20copied%20last%20time.%20In%20this%20blog%2C%20we%20will%20talk%20about%20several%20best%20practices%20of%20using%20ADF%20copy%20activity%20to%20achieve%20that%20use%20case.%20%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhen%20we%20try%20to%20come%20up%20with%20the%20best%20approaches%20to%20copy%20new%20files%20only%2C%20it%20is%20impossible%20to%20achieve%20that%20without%20understanding%20your%20data%20pattern%20as%20well%20as%20the%20scenario%20environment.%20Given%20that%2C%20we%20will%20illustrate%204%20different%20scenarios%20below%20with%20the%20best%20practices%20for%20each%20of%20using%20ADF%20to%20copy%20new%20files%20only.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EScenario%201%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EIf%20your%20files%20become%20useless%20in%20source%20store%20after%20being%20moved%20to%20the%20destination%20store%2C%20we%20suggest%20you%20to%20simply%20delete%20files%20from%20source%20store%20after%20successfully%20moving%20them%20to%20the%20destination%20store%20by%20setting%20%3CEM%3E%E2%80%9CdeleteFilesAfterCompletion%E2%80%9D%3C%2FEM%3E%20as%20true%20in%20copy%20activity.%20%26nbsp%3BBy%20doing%20so%2C%20all%20the%20files%20which%20show%20up%20in%20source%20store%20are%20new%20files%20by%20nature.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22copywithdelete.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206306i379B0B15946A99BB%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22copywithdelete.png%22%20alt%3D%22copywithdelete.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EScenario%202%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EIf%20the%20files%20can%20not%20be%20deleted%20from%20data%20source%20after%20being%20moved%20to%20the%20destination%2C%20you%20can%20find%20if%20your%20folders%20or%20files%20are%20time-based%20partitioned%20or%20not.%20For%20example%2C%20your%20folder%20structure%20may%20follow%20the%20pattern%20like%20%3CEM%3E%E2%80%9Cyyyy%2Fmm%2Fdd%2F%E2%80%9D%3C%2FEM%3E.%20If%20so%2C%20you%20can%20leverage%20the%20ADF%20system%20variable%20with%20parameter%20to%20get%20the%20new%20files%20only%20via%20time%20partitioned%20folder%20name%20or%20file%20name.%26nbsp%3B%20You%20can%20do%20this%20following%20the%20instruction%20below%3A%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fdata-factory%2Ftutorial-incremental-copy-partitioned-file-name-copy-data-tool%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EADF%20tutorial%20on%20incremental%20copy%20from%20time%20partitioned%26nbsp%3Bfolder%20name%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EScenario%203%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EIf%20your%20data%20pattern%20is%20not%20belong%20to%20scenario%20%231%20or%20%232%2C%20you%20can%20try%20to%20find%20if%20your%20file%20property%20%E2%80%9CLastModifiedDate%E2%80%9D%20can%20be%20used%20to%20differentiate%20the%20new%20files%20from%20the%20old%20ones.%26nbsp%3B%20If%20so%2C%20you%20can%20copy%20the%20new%20and%20changed%20files%20only%20by%20setting%20%3CEM%3E%22%3C%2FEM%3E%3CSPAN%3E%3CEM%3EmodifiedDatetimeStart%22%3C%2FEM%3E%20and%20%3CEM%3E%22modifiedDatetimeEnd%22%3C%2FEM%3E%20in%20ADF%20dataset%3C%2FSPAN%3E.%20ADF%20will%20scan%20all%20the%20files%20from%20the%20source%20store%2C%20apply%20the%20file%20filter%20by%20their%20LastModifiedDate%2C%20and%20only%20copy%20the%20new%20and%20updated%20file%20since%20last%20time%20to%20the%20destination%20store.%20Please%20be%20aware%20if%20you%20let%20ADF%20scan%20huge%20amounts%20of%20files%20but%20only%20copy%20a%20few%20files%20to%20destination%2C%20you%20would%20still%20expect%20the%20long%20duration%20due%20to%20file%20scanning%20is%20time%20consuming%20as%20well.%3C%2FP%3E%0A%3CP%3EYou%20can%20go%20with%20the%20following%20instructions%20as%20below%3A%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fdata-factory%2Ftutorial-incremental-copy-lastmodified-copy-data-tool%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EADF%20tutorial%20on%20incremental%20copy%26nbsp%3Bvia%26nbsp%3BLastModifiedDate%20%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fdata-factory%2Fsolution-template-copy-new-files-lastmodifieddate%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EADF%20template%20on%26nbsp%3Bincremental%20copy%26nbsp%3Bvia%26nbsp%3BLastModifiedDate%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EScenario%204%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EIf%20none%20of%20approaches%20above%20can%20be%20used%20in%20your%20scenario%2C%20you%20need%20to%20build%20a%20custom%20way%20to%20get%20the%20file%20list%20of%20new%20files%2C%20and%20send%20the%20new%20file%20list%20to%20ADF%20to%20copy%20them.%20ADF%20copy%20activity%20can%20consume%20a%20text%20file%20that%20includes%20a%20list%20of%20files%20you%20want%20to%20copy.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22copywithnewfilelist.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206307i969683EB0CA43839%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22copywithnewfilelist.png%22%20alt%3D%22copywithnewfilelist.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EMore%20information%20as%20below%3A%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fdata-factory%2Fconnector-amazon-simple-storage-service%23file-list-examples%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EExample%20of%20file%26nbsp%3Bincluding%20a%20list%20of%20files%20name%20to%20copy%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1532484%22%20slang%3D%22en-US%22%3E%3CP%3EAzure%20Data%20Factory%20now%20supports%20copying%20new%20files%20only%20via%20copy%20activity%20in%204%20different%20data%20ingestion%20scenarios.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1532484%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Data%20Factory%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ECopy%20Activity%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

In on-going ELT scenario, how to easily load new files only after an initial full data loading is a very common use case. One of the typical examples is that files can be continually dropped to a landing folder of your source store, where you want an easy way to copy the new files only to data lake store instead of repeatedly copy any files which have already been copied last time. In this blog, we will talk about several best practices of using ADF copy activity to achieve that use case.  

 

When we try to come up with the best approaches to copy new files only, it is impossible to achieve that without understanding your data pattern as well as the scenario environment. Given that, we will illustrate 4 different scenarios below with the best practices for each of using ADF to copy new files only.

 

Scenario 1:

If your files become useless in source store after being moved to the destination store, we suggest you to simply delete files from source store after successfully moving them to the destination store by setting “deleteFilesAfterCompletion” as true in copy activity.  By doing so, all the files which show up in source store are new files by nature.

copywithdelete.png

 

Scenario 2:

If the files can not be deleted from data source after being moved to the destination, you can find if your folders or files are time-based partitioned or not. For example, your folder structure may follow the pattern like “yyyy/mm/dd/”. If so, you can leverage the ADF system variable with parameter to get the new files only via time partitioned folder name or file name.  You can do this following the instruction below: 

ADF tutorial on incremental copy from time partitioned folder name

 

Scenario 3:

If your data pattern is not belong to scenario #1 or #2, you can try to find if your file property “LastModifiedDate” can be used to differentiate the new files from the old ones.  If so, you can copy the new and changed files only by setting "modifiedDatetimeStart" and "modifiedDatetimeEnd" in ADF dataset. ADF will scan all the files from the source store, apply the file filter by their LastModifiedDate, and only copy the new and updated file since last time to the destination store. Please be aware if you let ADF scan huge amounts of files but only copy a few files to destination, you would still expect the long duration due to file scanning is time consuming as well.

You can go with the following instructions as below:

ADF tutorial on incremental copy via LastModifiedDate

ADF template on incremental copy via LastModifiedDate

 

Scenario 4:

If none of approaches above can be used in your scenario, you need to build a custom way to get the file list of new files, and send the new file list to ADF to copy them. ADF copy activity can consume a text file that includes a list of files you want to copy.

copywithnewfilelist.png

More information as below:

Example of file including a list of files name to copy