BlogFileMaker

Use System Level Scripts to Archive Backups or FTP Import with FileMaker Server

By September 21, 2011 6 Comments

System level scripts can be very helpful to use with FileMaker Server. There are two problems I was able to solve by using system level scripts, and now I use these two processes on a daily basis. The first problem I came across was that the server machine was always running out of memory.

To solve this, I created a process that creates a zip file of my backup. It then move the backup to another machine. The second issue I came across was a client needed to refresh FileMaker data from another data source on a nightly basis.

Using ftp to access a machine and then grabbing a file to import it into FileMaker solved this request. I will go into how to do each of these in detail.

Creating Zip Files of the Backup and Moving Them to Another Location

This example assumes you are on a Mac.

  1. First, set up a schedule that keeps only one backup in the folder. In this example, I call that backup “ScriptedBackups.” For this particular client, I have a development FileMaker file and a production FileMaker file, so I need to create a back up schedule for each one with it’s own separate folder:
    1. /Volumes/Server HD/Library/FileMaker Server/Data/Backups/ScriptedBackups/Production/
    2. /Volumes/Server HD/Library/FileMaker Server/Data/Backups/ScriptedBackups/Development/
  2. Once you have the backup schedule ready, you can create the shell script to zip up the file and then move it to the proper location. Put the scripts in the scripts folder within FileMaker Server (Library/FileMaker Server/Data/Scripts/).  The set of scripts available below were written by Jeremiah Small (thank you!). The zip_daily.sh script defines 2 variables:  the starting path and the target path. You need to update those 2 paths, and the path to the worker script. The shell script will call the worker script to do all the work; it also adds data to the logger, so you can monitor results. zip_dailysh.sh zip_workersh.sh. A worker script allows you to create as many calling scripts as you wish. You only have to update the two paths. For example, we use a zip_daily.sh, zip_hourly.sh, zip_monthly.sh, and a zip_weekly.sh, and they all call the same worker script.
  3. Create a new schedule that calls the system level script appropriately. If you call your script zip_daily.sh, create a schedule that calls the script daily.
  4. Test Now you are done!

Tips:

  • FileMaker server always runs scripts from the root, so file paths need to be absolute, not relative.
  • You can also use this same logic to create a schedule that deleted files that are older than x number of days. For example, see purge_183dayssh.txt and purge_workersh.sh (In this calling file, you will need to update all the filepaths).

FTP into Site and Move Files Locally to Import

The example assumes you are on a PC.

  1. First thing to do is create the scripts to ftp into a server and grab a file. Thank you to Mason Dixon for creating these scripts. He set it up so there is a calling batch script and a corresponding text file with the information. For this example, I want to grab unit_import.csv from the ftp site and move it locally to my documents folder inside of FileMaker server. In the text file, edit the ftp site, user name, password, and destination path as desired. Make sure the path and name of the text file are correct in the batch file. The scripts should be living in “C:Program FilesFileMakerFileMaker ServerDataScripts” and the data files should be living in “C:Program FilesFileMakerFileMaker ServerDataDocuments” doftp_unit_importbat.txt ftpdirectives_unit_import.txt
  2. Once you have your scripts in place, you want to create a FileMaker Server schedule. The trick here is to use a script sequence schedule, because you don’t want to import the data until the import file has completed its move to the local machine. Create a script sequence to call the batch script you created in step one and then call an import script from FileMaker.
  3. Test Now you are done!

Tips:

  • This example assumes the import filename and location never changes.
  • In the system level scripts, the filename is case sensitive, so be sure it matches the name of the file on the FTP server.
  • If the file to be imported doesn’t live in the root of the ftp site, then you can change directory by adding “cd newdirectory” to the text file, before the lcd step.
  • If you have issues moving the file from the ftp site, make sure to add ftp.exe as an exception to your firewall.
  • You can also use the same logic to export a file from FileMaker, and then move it to an ftp site. For example, see doftp_local_law_exportbat.bat and ftpdirectives_local_law_export.txt.

Down the scripts.

I hope you find this as useful as I did. I’d be happy to answer any questions via comments or email:  mencarnacao@soliantconsulitng.com

Thanks for reading!

Makah Encarnacao

Makah Encarnacao

Makah Encarnacao

Makah is a Senior Technical Project Lead that hails from Albuquerque, NM. She joined Soliant a few months after graduating from UCLA in 2007, and must like it a lot because she’s still here! She is certified in FileMaker 9, 10, 11, 12, 13, 14, 15, 16 and 17, and placed 4th in the 2015 FileMaker DevCon Developer Cup. She was a speaker at the 2016 and 2018 FileMaker Conference. When she is not coding, she is enjoying life with her family that recently increased by 1.

6 Comments

  • Avatar Olly says:

    Hi Makah & Jeremiah

    Thanks for those, most useful for the toolbox (esp PC ftp – not my native tongue)

    Just discovered collapsible list post too, very cool.

    Thanks

    Olly
    London, UK

  • Avatar Andreas says:

    Thank you very much!

    I try to create my first Filemaker Server Systemlevel Script.
    But it always stops with the Error “Aborted by user”.

    Do you have any idea what i can do?

    (i have tried the default user, and also an Admin-User)

    Greetings

    Andreas

  • Avatar Makah Encarnacao says:

    Hi Andreas, do you have a time limit on your schedule?  Have you tried extending that time or turning that limit off?

  • Avatar Kitty says:

    Thank you for the info!

    How do I create a Filemaker script that calls for an import from that specific file. I can’t seem to get filemaker to recognize the file path.

    Kitty

  • Avatar John says:

    Hi,

    Your script runs until the following point on my computer

    “Thors-MacBook-Air:/ Thor$ /Library/FileMaker\ Server/Data/Scripts/zip.worker.sh
    ln: /tmp/soliant001.ln: Invalid argumen”

    How would I modify it to run correctly?

    Thanks,

    John

  • Avatar Makah Encarnacao says:

    Hi John, 

    zip_workersh.sh should not have to be modified. But any scripts that call this script will need to be modified. Have you updated the calling script correctly? It seems like it might be a path issue.

Leave a Reply

Need to adjust your business processes quickly? We're helping clients use technology to keep their teams productive and running smoothly in these times of uncertainty. Our team can guide yours if you need help in these areas.

Talk to a Consultant