Nextcloud Docker Backup with DB

  • hi all,


    nextcloud is setup using the well known tutorial by @macom.


    problems and additional thinks are fixed with the support topic.



    now, all is running well and configured (moved from google to my nextcloud inkl. contacts, calender and thinks like this) i come to the ask "what will happen if my system crash some time, or i have to resetup - maybe for omv6 oder 7 or what ever ...



    backing up the data part of nextcloud is not the problem, i just let it resync to another location.


    also found a little script to backup my calenders and contacts - but - what is to do to backup the database - and how to restore in the case of need.



    what are your solutions?


    i have no experiance with db - most cases i have to use db in the past was just "click next in setup, say yes to all and just run your program" never need to work with the db - in most cases a reinstall on other system works like "copy the file xyz.db to the folder "bla\" and start the program, it will find the db and work with this db" ... xD



    best (for me) would be a script for given setup (nextcloud in docker etc.pp) with the opinion to backup and restore - to just let it run with a cronjob.


    it's done - follow if you don't want to read the monologue ^^


    thx ;)

  • hi,


    need little help ;)


    found this: https://decatec.de/home-server…-manuell-oder-per-skript/ for the non german: just look the code at: https://codeberg.org/DecaTec/N…master/NextcloudBackup.sh



    looks good to me, so i will try to "convert" it to "our" project here - whats about the "stop web server" (and start) section - will it be the same (for us) just to stop the nextcloud container? or can someone tell me how to stop it after i do a docker exec -it -u abc nextcloud bash



    thx so far

  • question still activ: whats about stopping the webserver - or - did we realy need it?


    but here we go, 1st version of the backup script works ;)



    again: its not my work - i just rework / customize it.


    would like some others to test (also test the restore what will follow the next days)
    somethink to do better?


    just add a little "bool" backupUserData - i backup this with rsync - so a switch to set it off was usefull :)


    have fun
    draddy

  • When I migrated my nextcloud to another machine I activated maintenance mode and copied the appdata folders to the new machine and threw up the dockers. So my backup strategy is just to take copies of the appdata folders.
    But your way might be cleaner :)

  • yeah maintain have to - but don't know if it is need to stop the webserver / docker ^^


    on your "way" whats about database? or just use nc for some files without that groupware stuff and so on? or did your database that just happy survive? xD


    will look for the restore script in the next step - and would be still happy if someone else could test it with me .. ;)

  • HELP ;)


    restorescipt:

    runs - looks good until it will set maintain fingerprint - and will appiere everytime occ is called
    to much for forum - just pastbin it


    webpage just bring up


    whats going wrong? whats to change? how to fix?
    thx

  • Quote

    on your "way" whats about database? or just use nc for some files without that groupware stuff and so on? or did your database that just happy survive? xD

    Yes it worked just like that.



    btw. which backup script for calendars and contacts are you using?

  • so it work better than mine (at the moment ^^)


    this is the calender / contacts stuff


    just put it all into one script like:



    any idea for my recovery desaster? xD

  • the groupware skript or the backup / restore?


    - looks like my table is empty - so the import didn't work .. questen - why ^^




    up again - copy the dump file to the container (just used the appdata/nextclouddb folder) and run mysql -h localhost --force -u"user" -p"password" nextcloud < /config/nextcloud-db.sql jin container shell ... all tables back nc running ...


    how to do this "extern" like i tryed with docker exec $dbDocker mysql -h localhost -u "${dbUser}" -p"${dbPassword}" "${nextcloudDatabase}" < "${currentRestoreDir}/${fileNameBackupDb}"


    have played around a little with this in ssh (so without vars) and also don't get it working - suggestions? (don't have to be a one liner, so if it is posible someshing like


    Code
    cp <backupfile> /appdata/nextclouddb
    docker exec -it nextclouddb bash
    mysql blabla < backupfile.sql
    exit

    would also be ok - would it work? or dose someone know why the oneliner isn't working? for all other stuff it runs smoth


    thx

  • finaly!
    seems to work now ... just a f*** little -i xD
    like we say in germany "das pünktchen auf dem i" ...


    docker exec -i $dbDocker mysql -h localhost -u "${dbUser}" -p"${dbPassword}" "${nextcloudDatabase}" < "${currentRestoreDir}/${fileNameBackupDb}" that little -i fix the hole think ..


    soo, here are the scripts: (on pastbin, 10.000 sign only / post ^^)
    Backup:


    nextcloudBackup.sh on pastbin


    Restore:


    nextcloudRestore.sh on pastbin


    questions? test results? improvements? - give it to me ;)


    thanks again to DecaTec from nextcloud forum to share the basic and say "yes" to everyone how wants to change / customize the script.


    gl, hf
    draddy

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!