How to backup and restore a Wordpress site in NixOS?

Hi everyone, I’m pretty new to nixos and wordpress in general and trying to learn both of them. Right now I have a basic config file for it and can setup, run and modify it in localhost. However I can’t seem to figure out a way to backup the frontend and content of the website. I tried using wp-backitup plugin but it doesn’t work for some reasons.

Let’s say I want to have my other laptop to use the same config file and have it get up and running with the exact same customized theme and blog content, how can I achieve this? Here is my wordpress.nix so far (taped together by following online tutorial and wiki).

{ config, pkgs, ... } :

let
  site-name = "my-website";

  # Auxiliary functions
  fetchPackage = { name, version, isTheme, hash}:
    pkgs.stdenv.mkDerivation rec {
      inherit name version hash;
      src = let type = if isTheme then "theme" else "plugin";
      in pkgs.fetchzip {
        inherit name version hash;
        url = "https://downloads.wordpress.org/${type}/${name}.${version}.zip";
      };
      installPhase = "mkdir -p $out; cp -R * $out/";
    };

  fetchPlugin = { name, version, hash }:
    (fetchPackage {
      name = name;
      version = version;
      hash = hash;
      isTheme = false;
    });

  fetchTheme = { name, version, hash }:
    (fetchPackage {
      name = name;
      version = version;
      hash = hash;
      isTheme = true;
    });

  # Plugins
  google-site-kit = (fetchPlugin {
    name = "google-site-kit";
    version = "1.132.0";
    hash = "sha256-eERxesB3ECqCuSC12sdajzSDXXR4OInK38jIk+Vt50A=";
    # hash = "sha256-8QZ4XTCKVdIVtbTV7Ka4HVMiUGkBYkxsw8ctWDV8gxs=";
  });

  wordpress-seo-latest = (fetchPlugin {
    name = "wordpress-seo";
    version = "23.2";
    hash = "sha256-k71WIwRaQsDemTqhREJQysb8VEBXivOsUb2COdyLseM=";
  });

  wp-backitup = (fetchPlugin {
    name = "wp-backitup";
    version = "1.50.0";
    hash = "sha256-UFdiO/B151mx9raT7XFchCvRCRjFlDif0TReQEZymqo=";
  });

  # Themes
  astra = (fetchTheme {
    name = "astra";
    version = "4.7.3";
    hash = "sha256-rYSvOsBQcAsAoHkDFINkCZSGN8UiOMcsDzghFcXOnRo=";
  });

  eksell = (fetchTheme {
    name = "eksell";
    version = "1.9.5";
    hash = "sha256-9IfIzZcz12kfepO1uvOZ0+ucaRQE8xpKNRB8mygu8JM=";
  });



in

{
  services.wordpress.sites.${site-name} = {
    plugins = {
      inherit google-site-kit wordpress-seo-latest wp-backitup;
    #   inherit (pkgs.wordpressPackages.plugins)
    #     wordpress-seo;
    };

    themes = {
      inherit astra eksell;
    };

    settings = {
      WP_DEBUG = true;
      WP_DEBUG_LOG = true;
    };

    extraConfig = ''
      ini_set( 'error_log', '/var/lib/wordpress/${site-name}/debug.log' );
    '';

  };

  services.wordpress = {
    webserver = "nginx";
  };
}

Thanks in advance.

2 Likes

Sorry, could you please provide more details on what doesn’t work and what you expect to happen?