{
    "version": "https://jsonfeed.org/version/1",
    "title": "Sr Izan's Blog",
    "home_page_url": "https://srizan.dev/blog",
    "feed_url": "https://srizan.dev/blog/feed.json",
    "description": "My little donowall place on the net",
    "icon": "https://srizan.dev/pfp.png",
    "author": {
        "name": "Sr Izan",
        "url": "https://srizan.dev"
    },
    "items": [
        {
            "id": "https://srizan.dev/blog/2",
            "content_html": "<h2>Introduction</h2>\n<p>So, the last few months I&#39;ve been migrating services from my good old Raspberry Pi into my new HP server and the last service I migrated was MongoDB.</p>\n<p>I&#39;ve been using MongoDB for a while now and I&#39;ve been using it for a few things, like my discord bots, <a href=\"https://github.com/SrIzan10/webhooks-ui\">webhooks-ui</a> and probably other projects I don&#39;t remember right now.</p>\n<p>So, let&#39;s get started!</p>\n<h2>Testing the plan</h2>\n<p>My database instance is on Docker with a replica set of 1 node (itself) so <a href=\"https://www.prisma.io/\">Prisma</a> works.</p>\n<p>My idea is to add the HP server as a secondary replica and then promote it to be the primary one, but I don&#39;t know if that will work, so we need to test some stuff.</p>\n<p>I first created 2 docker containers on my <a href=\"https://gist.github.com/SrIzan10/50bc2ba689a4cc43bcbac2799cc733c9\">main Ryzen machine</a>&#39;s WSL Ubuntu instance.</p>\n<p>I created a <code>docker-compose.yml</code> file with the following content:</p>\n<pre><code class=\"language-yml\">version: &quot;3.8&quot;\nservices:\n  mongo1:\n    image: mongo:4.4.17-rc0-focal\n    container_name: mongo1\n    restart: always\n    ports:\n      - 27017:27017\n    volumes:\n      - ./mongo1:/data/db\n    command: mongod --replSet mongoset\n    networks:\n      - mongo\n  mongo2:\n    image: mongo:4.4.17-rc0-focal\n    container_name: mongo2\n    restart: always\n    ports:\n      - 27018:27017\n    volumes:\n      - ./mongo2:/data/db\n    command: mongod --replSet mongoset\n    networks:\n      - mongo\nnetworks:\n  mongo:\n</code></pre>\n<p>and ran it with <code>docker compose up -d</code>.</p>\n<p>I went to connect with MongoDB Compass and it didn&#39;t work for some reason. I asked GPT and nothing. It looks like it accepted the connection but it won&#39;t connect, so I installed <code>mongosh</code> and tried to connect with that.</p>\n<pre><code class=\"language-bash\">$ mongosh mongodb://localhost:27017\n</code></pre>\n<p>...and it worked! That didn&#39;t make any sense, but okay, we can work with it.</p>\n<p>I then connected to the <code>mongo1</code> instance and ran the following commands:</p>\n<pre><code class=\"language-bash\">&gt; rs.initiate()\n</code></pre>\n<p>and it worked, but only that same database connected. Before adding the second database to the replica, I went ahead and pinged it from the first container (just to check if the network configuration worked):</p>\n<pre><code class=\"language-bash\">docker exec mongo1 sh -c &quot;rm /bin/ping;apt update;apt install inetutils-ping -y;ping mongo2&quot;\n</code></pre>\n<p>I removed /bin/ping because I tried to transfer the binary from WSL to the container but it still needed some libraries and I didn&#39;t want to bother, so I just installed the package.</p>\n<p>It worked, so I went ahead and added the second database to the replica set:</p>\n<pre><code class=\"language-bash\">&gt; rs.add(&quot;mongo2&quot;)\n</code></pre>\n<p>After waiting for it, the second database connected and everything was working fine. Let&#39;s create a collection and some documents on the primary replica (mongo1):</p>\n<pre><code class=\"language-bash\">&gt; use test\n&gt; db.createCollection(&quot;test&quot;)\n&gt; db.test.insertOne({ name: &quot;test&quot; })\n</code></pre>\n<p>and then, let&#39;s check if it&#39;s on the second replica (mongo2):</p>\n<pre><code class=\"language-bash\">$ mongosh mongodb://localhost:27017\n</code></pre>\n<pre><code class=\"language-bash\">&gt; use test\n&gt; db.getMongo().setReadPref(&quot;secondaryPreferred&quot;)\n&gt; db.test.find()\n</code></pre>\n<p>and, yeah, that worked.</p>\n<p>I don&#39;t really know if ORMs will read when connecting to the second replica, but for now it&#39;s fine as the main plan is on track.<br>So, to promote I connected to the primary replica (mongo1) and ran the following command:</p>\n<pre><code class=\"language-bash\">&gt; rs.stepDown()\n</code></pre>\n<p>And that worked! Woo! The second replica is now the primary one. We can now start <em>drum rolls please</em>:</p>\n<h2>The migration</h2>\n<p>This is it. We&#39;re doing it.</p>\n<p>I went ahead and created a new docker-compose file on my server with the following content:</p>\n<pre><code class=\"language-yml\">version: &quot;3.8&quot;\nservices:\n    mongo:\n        image: mongo:4.4.17-rc0-focal\n        container_name: mongodb\n        restart: unless-stopped\n        ports:\n            - 27017:27017\n        volumes:\n            - ./mongo:/data/db\n        command: mongod --replSet rs0\n</code></pre>\n<p>After deploying the stack, I connected using mongosh to the primary db and ran the following command:</p>\n<pre><code class=\"language-bash\">&gt; rs.add(&quot;ip&quot;)\n</code></pre>\n<p>and after waiting for a while it looked like it worked. I then connected to the new database and ran the following command to check if the replica cloned fine:</p>\n<pre><code class=\"language-bash\">&gt; db.getMongo().setReadPref(&quot;secondaryPreferred&quot;)\n</code></pre>\n<p>and let&#39;s just let the results speak for themselves:</p>\n<pre><code class=\"language-bash\">rs0 [direct: secondary] test&gt; show dbs\n# author&#39;s note: some dbs are redacted for privacy reasons \nadmin         80.00 KiB\napi           80.00 KiB\nava           40.00 KiB\nbask         168.00 KiB\nconfig       144.00 KiB\nlocal        348.00 KiB\nvinci        428.00 KiB\nrs0 [direct: secondary] test&gt; use vinci\nswitched to db vinci\nrs0 [direct: secondary] vinci&gt; show tables\nafk\nbirthdays\nchatgpt\ngiveaways-enters\ngiveaways-message\npadyama\nsuggestions\ntwitter\nwarns\nyoutube\nrs0 [direct: secondary] vinci&gt; db.afk.find()\n[\n  {\n    _id: ObjectId(&quot;sadfsad fsadfsdf&quot;),\n    id: &#39;redacted&#39;,\n    reason: &#39;redacted&#39;,\n    __v: 0\n  },\n  {\n    _id: ObjectId(&quot;asdfsadfadf&quot;),\n    id: &#39;redacted&#39;,\n    reason: &#39;readacted&#39;,\n    __v: 0\n  }\n]\nrs0 [direct: secondary] vinci&gt;\n</code></pre>\n<p>Nice. let&#39;s now try to write something to the database from Vinci:<br><img src=\"https://img.srizan.dev/Discord_a2iXkWYxwn.png\" alt=\"\"><br>That just worked and we can see it on the secondary replica:</p>\n<pre><code class=\"language-bash\">rs0 [direct: secondary] vinci&gt; db.afk.find({ id: &#39;703974042700611634&#39; })\n[\n  {\n    _id: ObjectId(&quot;6550eccc6154a8c9030fe76a&quot;),\n    id: &#39;703974042700611634&#39;,\n    reason: &#39;test&#39;,\n    __v: 0\n  }\n]\n</code></pre>\n<p>Let&#39;s now edit all .envs and change the database url to the new secondary one. For this I checked all dbs that I have and then go from top to bottom editing the secrets.</p>\n<p>After that was done I needed to deploy all changes. I went ahead and created too many tabs on my terminal and ran the all deployment commands on each tab. At the same time.<br>I really hope that doesn&#39;t make my server run out of ram, because I&#39;m really short on that.</p>\n<p>After executing all the commands I <code>rs.stepDown()</code>&#39;ed the primary Raspberry Pi replica and, as expected, the HP Server took over.</p>\n<p>The last command of the day:</p>\n<pre><code class=\"language-bash\">&gt; rs.remove(&quot;ip&quot;)\n</code></pre>\n<p>...SIKE! I needed to check the logs of the containers to see if everything was working fine. The <code>api</code> and <code>vinci</code> to be exact.<br>This is because <code>api</code> runs Prisma and <code>vinci</code> runs the now defunct in my stack, <a href=\"https://mongoosejs.com/\">mongoose</a>.</p>\n<p>Luckily enough, both were fine, so I was free. Yay!</p>\n<h2>Conclusion</h2>\n<p>Welp, that was a lot of work. I&#39;m glad it&#39;s over. I got my HP server on July and it&#39;s now November and I just finished migrating.<br>Could I have done it in less time? Yes.<br>Was I lazy? Also yes.</p>\n<p>So that answers all your questions.</p>\n<p>I hope you enjoyed this my first blog post, and thankfully it was a big one.<br>This took 3 hours in total, but at the end of the day, it was worth it.</p>\n<p>I&#39;ll see you in the next one!</p>\n",
            "url": "https://srizan.dev/blog/2",
            "title": "My tales of MongoDB migration",
            "summary": "Here I ramble about the last service migration I did, MongoDB, and all the difficulties that came with it.",
            "date_modified": "2023-11-11T23:00:00.000Z",
            "author": {
                "name": "Sr Izan",
                "url": "https://srizan.dev"
            }
        },
        {
            "id": "https://srizan.dev/blog/3",
            "content_html": "<p>Alright, let&#39;s do this. Fast.<br>Disclaimer: this only works when the /home directory is on the same partition, which is the default option if you don&#39;t specify.</p>\n<h1>Step 1: Boot up a live environment.</h1>\n<p>For the sake of simplicity, I&#39;ll be using the Endeavour OS Galileo installation media, but <a href=\"https://command-not-found.com/arch-chroot\">any linux distro should work</a></p>\n<p>When you&#39;re in, open the terminal:<br><img src=\"https://img.srizan.dev/vmware_zCwt9ac9KE.png\" alt=\"\"></p>\n<h1>Step 2: Mounting the linux distro</h1>\n<p>Type in <code>lsblk</code>. This will show all mounted drives.<br><img src=\"https://img.srizan.dev/vmware_LPBNlTo9BI.png\" alt=\"\"></p>\n<p>Locate the drive and partition where your installation is.<br>It&#39;s usually the partition with the most space. The space is on the size row (duh)<br>If you have multiple drives with the same size and want more info about the volumes, type in <code>fdisk -l</code>.</p>\n<p>In my case it&#39;s <code>/dev/sda1</code>.</p>\n<p>So let&#39;s mount the partition to the <code>/mnt</code> directory with <code>sudo mount /dev/sda1 /mnt</code>.  </p>\n<h1>Step 3: Chrootin&#39;</h1>\n<p>Chroot is a linux tool which basically changes the root directory to whatever directory you specify. This will be used to run the <code>passwd</code> command inside your installation&#39;s context.</p>\n<p>Arch Linux has it&#39;s own chroot command which does some magic in the background to make it useable on this distro&#39;s environments.</p>\n<pre><code class=\"language-sh\">sudo arch-chroot /mnt\n</code></pre>\n<p>should chroot into your installation and after a few seconds a shell will show up!<br><img src=\"https://img.srizan.dev/vmware_nyyqOA9ELo.png\" alt=\"\"></p>\n<p>And now one last command, the one that actually changes the password:</p>\n<pre><code class=\"language-sh\">passwd yourusername\n</code></pre>\n<p>and boom! that&#39;s it! impressive, right? <code>exit</code> off the console and then reboot.</p>\n<h1>The end</h1>\n<p>That was quick.</p>\n",
            "url": "https://srizan.dev/blog/3",
            "title": "How to change the user password in Arch Linux if you forgot it",
            "summary": "This post was made for a certain person who loves to lose passwords",
            "date_modified": "2023-11-22T23:00:00.000Z",
            "author": {
                "name": "Sr Izan",
                "url": "https://srizan.dev"
            }
        },
        {
            "id": "https://srizan.dev/blog/1",
            "content_html": "<h1>Hey!</h1>\n<p>This is probably the last time I&#39;m going to make a blog. I&#39;ve made a few in the past, but I&#39;ve never really stuck to them. I&#39;m hoping that this time will be different.<br>This one was made entirely from scratch using React and Markdown, initially trying to use MDX, but it was a pain to set up, and it didn&#39;t end up working in the end.<br>I&#39;m hoping to post about my projects, and maybe some other stuff too. I&#39;m not sure yet, but I&#39;ll figure it out as I go along.<br>Anyways, thank you for reading. I hope you enjoyed my UX/UI for this one!</p>\n<p>PD: I need some help for making the blog text look good and readable, so hit me up on my Discord if you have any ideas.</p>\n",
            "url": "https://srizan.dev/blog/1",
            "title": "Welcome to my new blog!",
            "summary": "This post welcomes you to my new blog",
            "date_modified": "2023-08-19T22:00:00.000Z",
            "author": {
                "name": "Sr Izan",
                "url": "https://srizan.dev"
            }
        }
    ]
}