get.porter.sh/porter@v1.3.0/cmd/porter/storage.go (about) 1 package main 2 3 import ( 4 "get.porter.sh/porter/pkg/porter" 5 "github.com/spf13/cobra" 6 ) 7 8 func buildStorageCommand(p *porter.Porter) *cobra.Command { 9 cmd := cobra.Command{ 10 Use: "storage", 11 Short: "Manage data stored by Porter", 12 Long: `Manage the data stored by Porter, such as credentials and installation data. 13 `, 14 Annotations: map[string]string{ 15 "group": "resource", 16 }, 17 } 18 19 cmd.AddCommand(buildStorageMigrateCommand(p)) 20 cmd.AddCommand(buildStorageFixPermissionsCommand(p)) 21 22 return &cmd 23 } 24 25 func buildStorageMigrateCommand(p *porter.Porter) *cobra.Command { 26 var opts porter.MigrateStorageOptions 27 cmd := &cobra.Command{ 28 Use: "migrate --old-home OLD_PORTER_HOME [--old-account STORAGE_NAME] [--namespace NAMESPACE]", 29 Short: "Migrate data from v0.38 to v1", 30 Long: `Migrate data from Porter v0.38 into a v1 installation of Porter. 31 32 See https://porter.sh/storage-migrate for a full description of the migration process. Below is a summary: 33 34 Before running this command, you should have: 35 36 1. Installed Porter v1, see https://porter.sh/install for instructions. 37 2. Renamed the old PORTER_HOME directory, for example: mv ~/.porter ~/.porterv0. 38 3. Created a new PORTER_HOME directory for the new version of Porter, for example: mkdir ~/.porter. 39 4. Configured a default storage account for the new version of Porter. The data from the old account will be migrated into the default storage account. 40 41 This upgrades the data to the current storage schema, and does not change the data stored in the old account. 42 43 This command may be repeated if it fails, is interrupted when first run, or new v0 data has been added. 44 Porter will restart the migration from the beginning and overwrite any previously migrated records. 45 🚨 After you use Porter v1 with the migrated database, DO NOT RERUN THE MIGRATION because subsequent migrations will overwrite data in the v1 database.`, 46 Example: ` porter storage migrate --old-home ~/.porterv0 47 porter storage migrate --old-account my-azure --old-home ~/.porterv0 48 porter storage migrate --namespace new-namespace --old-home ~/.porterv0 49 `, 50 RunE: func(cmd *cobra.Command, args []string) error { 51 return p.MigrateStorage(cmd.Context(), opts) 52 }, 53 } 54 55 flags := cmd.Flags() 56 flags.StringVar(&opts.OldHome, "old-home", "", 57 "Path to the old PORTER_HOME directory where the previous version of Porter is installed") 58 flags.StringVar(&opts.OldStorageAccount, "old-account", "", 59 "Name of the storage account in the old Porter configuration file containing the data that should be migrated. If unspecified, the default storage account is used.") 60 flags.StringVarP(&opts.Namespace, "namespace", "n", "", 61 "Destination namespace where the migrated data should be saved. By default, Porter migrates your data into the current namespace as configured by environment variables and your config file, otherwise the global namespace is used.") 62 return cmd 63 } 64 65 func buildStorageFixPermissionsCommand(p *porter.Porter) *cobra.Command { 66 return &cobra.Command{ 67 Use: "fix-permissions", 68 Short: "Fix the permissions on your PORTER_HOME directory", 69 Long: `This will reset the permissions on your PORTER_HOME directory to the least permissions required, where only the current user has permissions.`, 70 RunE: func(cmd *cobra.Command, args []string) error { 71 return p.FixPermissions(cmd.Context()) 72 }, 73 } 74 }