Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to upgrade the running memos container without losing data? #624

Closed
erbanku opened this issue Nov 28, 2022 · 10 comments
Closed

How to upgrade the running memos container without losing data? #624

erbanku opened this issue Nov 28, 2022 · 10 comments

Comments

@erbanku
Copy link

erbanku commented Nov 28, 2022

Thanks for making this awesome software. After installing & running memos (Sorry, I am new to docker) how can I update the container?

I am able to update the image, but unable to apply this update to the running memos container. Can you help me out? Thanks.

@Zeng1998
Copy link
Contributor

There are too many ways, it's up to you.

For me, I like to use raw docker commands.

  1. backup your database file (~/.memos/memos_prod.db), it's optional.
  2. stop the running container.
  3. remove the container.
  4. remove the image.
  5. get the latest image and run a new container. (https://github.com/usememos/memos#docker-run)

@erbanku
Copy link
Author

erbanku commented Nov 28, 2022

Success, awesome! Thanks.

@erbanku erbanku closed this as completed Nov 28, 2022
@AssistantLiu
Copy link

vim updatememos.sh
chmod 777 updatememos.sh

# Onekey update memos to latest

# list running container
docker ps

# list all exist images
docker images

# backup db
cp ~/.memos/memos_prod.db .

# rm container
docker rm -f memos

# rm image
docker rmi neosmemo/memos:latest

# update to latest
docker run -d --name memos -p 5230:5230 -v ~/.memos/:/var/opt/memos neosmemo/memos:latest

@erbanku
Copy link
Author

erbanku commented Dec 29, 2022

@AssistantLiu Thanks a lot.

@erbanku
Copy link
Author

erbanku commented Dec 29, 2022

Changed a bit.

# This script is used to update memos to the latest version.

# backup db with timestamp
cp ~/.memos/memos_prod.db ~/Backup/memos-db-backup/$(date +%Y%m%d%H%M%S).memos_prod.db

# rm container
docker rm -f memos
# rm image
docker rmi neosmemo/memos:latest

# Update to latest
docker run -d --name memos -p 5230:5230 -v ~/.memos/:/var/opt/memos neosmemo/memos:latest
# Get Docker memo container id and save this to variable memos_id
memos_id=$(docker ps | grep memos | awk '{print $1}')


# Enable docker service to run on startup
sudo systemctl enable docker.service
# Setup memos docker container to run on startup
docker update --restart=always $memos_id

@louzc
Copy link

louzc commented Jan 19, 2023

If you are the admin of the server, you can also use watchtower

@erbanku
Copy link
Author

erbanku commented Jan 19, 2023

I will try it out. Thanks. 😉

@JeauLiang
Copy link

These codes are backup the database and recreate the container, how can I restore the database after recreate the container?

@woshichenghaibo
Copy link

These codes are backup the database and recreate the container, how can I restore the database after recreate the container?

同问

@hossain-khan
Copy link

hossain-khan commented Jun 7, 2024

📝 UPDATE

I was able to restore all memos to new docker container instance. Instead of just coping the db file memos_prod.db you have to copy all 3 files. Then it works perfectly, including admin account. ✅

Now, my /portainer/Files/AppData/Config/memo-notes/ contains all 3 files before creating the container.

  • memos_prod.db
  • memos_prod.db-shm
  • memos_prod.db-wal

I have copied the memos_prod.db file from one container to another to replicate the whole instance. It didn't work.

I got the following error

---
Server profile
version: 0.22.1
data: /var/opt/memos
dsn: /var/opt/memos/memos_prod.db
addr: 
port: 5230
mode: prod
driver: sqlite
---
2024/06/07 02:46:19 ERROR failed to migrate database !BADKEY="SQL logic error: no such table: migration_history (1)\nfailed to find migration history\ngithub.com/usememos/memos/store/db/sqlite.(*DB).Migrate\n\t/backend-build/store/db/sqlite/migrator.go:49\nmain.init.func1\n\t/backend-build/bin/memos/main.go:52\ngithub.com/spf13/cobra.(*Command).execute\n\t/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:987\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\t/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115\ngithub.com/spf13/cobra.(*Command).Execute\n\t/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039\nmain.Execute\n\t/backend-build/bin/memos/main.go:100\nmain.main\n\t/backend-build/bin/memos/main.go:183\nruntime.main\n\t/usr/local/go/src/runtime/proc.go:271\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_arm64.s:1222"

Used following compose command

version: "3.0"
services:
  memos:
    image: neosmemo/memos:stable
    container_name: memos
    volumes:
      - /portainer/Files/AppData/Config/memo-notes/:/var/opt/memos
    ports:
      - 5230:5230

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants