You can save the global metadata to a text file using the -f ffmetadata option as follows:
ffmpeg -i in.mp4 -f ffmetadata in.txt
If you also need metadata from the video and audio streams (for example if the global metadata does not contain the creation time) use:
ffmpeg -i in.mp4 -c copy -map_metadata 0 -map_metadata:s:v 0:s:v -map_metadata:s:a 0:s:a -f ffmetadata in.txt
For details, see Metadata section in ffmpeg documentation.
For restoring metadata from a file see https://stackoverflow.com/a/50580239/2235831.