Last active
February 16, 2018 07:22
-
-
Save dongyuwei/a0d62f926fad9de7476346c49422713b to your computer and use it in GitHub Desktop.
This is a simple ruby script to backup react-native AsyncStorage in iOS Simulator. So we can backup and restore the whole redux store in AsyncStorage for development.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# backup workbench.app's AsyncStorage filesystem, so we can restore the whole redux store for development. | |
require "open3" | |
Open3.popen3("ps ax | grep workbench.app | awk '{print $5}' ") { |stdin, stdout, stderr| | |
process_name = stdout.readlines()[0] | |
base_dir = process_name.split('/data/')[0] | |
# Ref: node_modules/react-native/React/Modules/RCTAsyncLocalStorage.m | |
async_storage_dir = `find #{base_dir} -name "RCTAsyncLocalStorage_V1"` | |
timestamp = `date +"%Y%m%d_%H%M_%S"` | |
backup_dir = "~/workbench_async_storage_backup/#{timestamp}" | |
`mkdir -p #{backup_dir}` | |
`cp -Rfp #{async_storage_dir.strip()} #{backup_dir}` | |
puts "workbench.app's AsyncStorage have been backuped to #{backup_dir}" | |
puts "You can restore it to #{async_storage_dir}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script only works for iOS.
Please replace
workbench.app
with your target react-native app in iOS Simulator.Ref: https://facebook.github.io/react-native/docs/asyncstorage.html