{"id":67,"date":"2023-05-23T08:57:51","date_gmt":"2023-05-23T07:57:51","guid":{"rendered":"https:\/\/fabrizio.vanzani.it\/?p=67"},"modified":"2023-05-23T10:16:54","modified_gmt":"2023-05-23T09:16:54","slug":"magento-session-migration-between-files-and-db","status":"publish","type":"post","link":"https:\/\/fabrizio.vanzani.it\/?p=67","title":{"rendered":"Magento session migration between files and db"},"content":{"rendered":"\n<p>Here a script that helps to migrate session data from files to db and other way round.<\/p>\n\n\n\n<p>Usage:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" style=\"font-size:.875rem;line-height:1.25rem\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"php script_session_migration.php &lt;method&gt; &lt;mode&gt; &lt;dryrun|save&gt; [session_id] \nmethods: db2files, files2db \nmodes: insert, replace, upsert (todo) \nExamples:\nphp script_session_migration.php db2files insert save  \nphp script_session_migration.php db2files insert dryrun  \nphp script_session_migration.php db2files insert save fefa51f32efe28770ba23401aa1769fd \nphp script_session_migration.php files2db insert save  \nphp script_session_migration.php files2db replace dryrun  \nphp script_session_migration.php files2db insert save fefa51f32efe28770ba23401aa1769fd\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9\">php<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">script_session_migration<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">php<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">&lt;<\/span><span style=\"color: #D8DEE9\">method<\/span><span style=\"color: #81A1C1\">&gt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">&lt;mode&gt;<\/span><span style=\"color: #D8DEE9FF\"> &lt;dryrun|save&gt; [session_id] <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">methods: db2files, files2db <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">modes: insert, replace, upsert (todo) <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">Examples:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">php script_session_migration.php db2files insert save  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">php script_session_migration.php db2files insert dryrun  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">php script_session_migration.php db2files insert save fefa51f32efe28770ba23401aa1769fd <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">php script_session_migration.php files2db insert save  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">php script_session_migration.php files2db replace dryrun  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">php script_session_migration.php files2db insert save fefa51f32efe28770ba23401aa1769fd<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Click here to download:<\/p>\n\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-e1e40388-c254-4959-b339-98dbf4a32958\" href=\"https:\/\/fabrizio.vanzani.it\/wp-content\/uploads\/2023\/05\/script_session_migration.php_.zip\">script_session_migration.php_<\/a><a href=\"https:\/\/fabrizio.vanzani.it\/wp-content\/uploads\/2023\/05\/script_session_migration.php_.zip\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-e1e40388-c254-4959-b339-98dbf4a32958\">Download<\/a><\/div>\n\n\n\n<p>Tested on: magento 2.3<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This script helps to migrate sessions between files and database.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,4],"tags":[24],"class_list":["post-67","post","type-post","status-publish","format-standard","hentry","category-2-x","category-magento","tag-session"],"_links":{"self":[{"href":"https:\/\/fabrizio.vanzani.it\/index.php?rest_route=\/wp\/v2\/posts\/67","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fabrizio.vanzani.it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fabrizio.vanzani.it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fabrizio.vanzani.it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fabrizio.vanzani.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=67"}],"version-history":[{"count":2,"href":"https:\/\/fabrizio.vanzani.it\/index.php?rest_route=\/wp\/v2\/posts\/67\/revisions"}],"predecessor-version":[{"id":71,"href":"https:\/\/fabrizio.vanzani.it\/index.php?rest_route=\/wp\/v2\/posts\/67\/revisions\/71"}],"wp:attachment":[{"href":"https:\/\/fabrizio.vanzani.it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=67"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fabrizio.vanzani.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=67"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fabrizio.vanzani.it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=67"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}